virtual-machine - 无法通过 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
无论您做什么,无论是卸载还是加载模块,这似乎都不起作用。
解决方案
由于您在同一会话中运行 AzureRm 和 Az 命令,因此您可以运行Enable-AzureRmAlias
以启用 AzureRM 兼容性别名。或者,建议在 Azure Powershell 上使用所有支持 az 模块的脚本,例如更改 Select-AzureRmSubscription
为Set-AzContext。
推荐阅读
- angularjs - 数据目标可以与路由器一起使用吗
- javascript - 承诺“终于”不起作用
- python - 可以在纱线客户端模式下启动 Dask 吗?
- postgresql - 当 count 与 string_agg 一起使用时在 postgres 中不正确计数?
- java - spring boot 1.5.x /hystrix.stream 执行器不工作
- c++ - libuv - 在没有多线程的情况下限制空闲事件的回调率而不阻塞线程
- npm - 如何查看 node_modules 依赖树?
- powerbi - 在查询编辑器(PowerBI 或 PowerQuery)中引用另一个表
- python - 了解 opencv 的 decomposeHomographyMat 输出
- macos - MacOS:使用 Finder 同步扩展中的 getxattr/setxattr