Virtual machine 无法通过AzurePowerShell部署VM某些powershell模块冲突

Virtual machine 无法通过AzurePowerShell部署VM某些powershell模块冲突,virtual-machine,azure-powershell,Virtual Machine,Azure Powershell,这似乎是一项相当直截了当的任务,但却面临挑战,无法理解到底是什么问题 目标:通过ARM模板提供虚拟机 第一步。以交互方式登录Azure 第二步。选择订阅 Select-AzureRmSubscription -SubscriptionId "xxxxxxxxxxxxxxxxxxxxxxx" 第三步。创建资源组 第四步。创建部署: New-AzResourceGroupDeployment -ResourceGroupName arm-template -TemplateFile azured

这似乎是一项相当直截了当的任务,但却面临挑战,无法理解到底是什么问题

目标:通过ARM模板提供虚拟机

第一步。以交互方式登录Azure

第二步。选择订阅

Select-AzureRmSubscription -SubscriptionId "xxxxxxxxxxxxxxxxxxxxxxx"
第三步。创建资源组

第四步。创建部署:

New-AzResourceGroupDeployment -ResourceGroupName arm-template
 -TemplateFile azuredeploy.json -TemplateParameterFile .\azuredeploy.parameters.json
然而,我得到一个如下的错误

WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the same script or
runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm
 modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM
modules. More information can be found here: https://aka.ms/azps-migration-guide.
New-AzResourceGroupDeployment : The 'New-AzResourceGroupDeployment' command was found in the module 'Az.Resources', but the module
could not be loaded. For more information, run 'Import-Module Az.Resources'.
At line:1 char:1
+ New-AzResourceGroupDeployment -ResourceGroupName arm-template -Templa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-AzResourceGroupDeployment:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
因此,我运行命令:

PS E:\OnlyOnMyPC\azure-quickstart-templates\active-directory-new-domain> Import-Module Az.Resources
WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the same script or
runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm
 modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM
modules. More information can be found here: https://aka.ms/azps-migration-guide.
Import-Module : AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the same
script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove
all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az
and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide.
At line:1 char:1
+ Import-Module Az.Resources
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (AzureRM.Profile...igration-guide.:String) [Import-Module], RuntimeException
    + FullyQualifiedErrorId : AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used
   in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' c
  mdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbo
 oks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide.,Microsoft.Power
Shell.Commands.ImportModuleCommand

无论您做什么,卸载或加载模块,这似乎都不起作用。

因为您在同一会话中运行AzureRm和Az命令,所以可以运行Enable AzureRmAlias来启用AzureRm兼容性别名。或者,建议使用Azure Powershell上支持az模块的所有脚本,例如将Select AzureRmSubscription更改为


您可以从

获取更多详细信息,请在运行az命令之前尝试运行Enable AzureRmAlias。我运行的是Azure PowerShell而不是Azure CLI命令,先生,它可以工作吗?是的,找到了!很好,理解我犯的错误。@学习者对于Az模块没有选择AzSubscription这样的命令,您可以选择使用Set-AzContext或启用AzureRmAlias,如前所述。