首页 > 解决方案 > 无法通过 AzurePowerShell 部署 VM 某些 powershell 模块冲突

问题描述

似乎是一项相当直接的任务,但面临挑战并且无法理解究竟是什么问题?

目标:通过 ARM 模板配置 VM

步骤 1. 登录到 Azure - 以交互方式

步骤 2. 选择订阅

Select-AzureRmSubscription -SubscriptionId "xxxxxxxxxxxxxxxxxxxxxxx"

步骤 3. 创建资源组

步骤 4. 创建部署:

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

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

标签: virtual-machineazure-powershell

解决方案


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

您可以从将 Azure PowerShell 从 AzureRM 迁移到 Az获得更多详细信息


推荐阅读