我在 powershell 脚本中使用了 Az 模块,该模块从 powershell 核心执行,但在从应用程序(.Net core SDK 2.1)执行脚本时出错。
$VMExistanceCheck = Get-azVM -ResourceGroupName $VMResourceGroup -Name $NewComputerName -ErrorAction SilentlyContinue
我检查了 Az.Compute 模块是否已导入那里。
我添加了Import-Module Az.compute -verbose -force
也在脚本里面添加了。
使用运行空间(System.Management.Automation,Version=6.1.0.0)从应用程序调用脚本时出现以下错误:
System.Management.Automation.RuntimeException:在模块“Az.Compute”中找到“Get-azVM”命令,但无法加载该模块。有关更多信息,请运行“Import-Module Az.Compute”。---> System.Management.Automation.CommandNotFoundException:在模块“Az.Compute”中找到“Get-azVM”命令,但无法加载该模块。有关更多信息,请运行“Import-Module Az.Compute”。
“Get-Module -ListAvailable”显示 Az.Compute 模块可用,但使用 Powershell 6 执行命令“import-module Az.Compute”时,没有导入任何内容。