我正在尝试在Windows Powershell中导入模块Az.compute。我早些时候已经导入了模块AzureRM,因为我需要一些自动化任务。
但是我收到错误消息:
PS X:\XXXXXXXXXXXXXXXXXX\PowerShell> Import-Module -Name Az.compute
WARNUNG: 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.
In Zeile:1 Zeichen:1
+ Import-Module -Name Az.compute
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (AzureRM.Profile...igration-guide.:String) [Import-Module], RuntimeExc
eption
+ FullyQualifiedErrorId : AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same se
ssion or used in the same script or runbook. If you are running PowerShell in an environment you control you can u
se the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Aut
omation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found he
re: https://aka.ms/azps-migration-guide.,Microsoft.PowerShell.Commands.ImportModuleCommand⏎
我的问题是,由于需要两个模块,如何在安装AzureRM模块的同时导入Az.compute模块?
谢谢。
最诚挚的问候,
Ronny Forberger
试图导入Az.compute模块。
答案 0 :(得分:0)
恐怕简短的回答是“否”。但是-如果您要支持旧的脚本和功能,则可以安装Az模块,然后使用Enable-AzureRmAlias。
您需要先删除AzureRM模块,然后再安装Az模块。
当然,您应该更新所有脚本以支持新模块,以便旧模块不会收到任何更新。
https://docs.microsoft.com/en-us/powershell/module/az.accounts/enable-azurermalias?view=azps-2.3.2
答案 1 :(得分:0)
您可以在不同的会话中同时安装和使用AzureRm和Az模块。当需要使用Az模块时,使用Az cmdlet打开一个新会话,必须对AzureRm模块执行相同的操作。为每个模块使用新会话。