在模块“Az.Compute”中找到“Get-azVM”命令,但无法加载该模块

SRo*_*Roy 5 powershell azure-powershell az

我在 powershell 脚本中使用了 Az 模块,该脚本从 powershell core 执行,但在从应用程序(.Net core SDK 2.1)执行脚本时出现错误。

$VMExistanceCheck = Get-azVM -ResourceGroupName $VMResourceGroup -Name $NewComputerName -ErrorAction SilentlyContinue

我检查了 Az.Compute 模块已导入那里。

Import-Module Az.compute -verbose -force也在脚本中添加了。

使用 runspace(System.Management.Automation, Version=6.1.0.0) 从应用程序调用脚本时出现以下错误:

System.Management.Automation.RuntimeException:在模块“Az.Compute”中找到“Get-azVM”命令,但无法加载该模块。有关详细信息,请运行“导入模块 Az.Compute”。---> System.Management.Automation.CommandNotFoundException:在模块“Az.Compute”中找到“Get-azVM”命令,但无法加载该模块。有关详细信息,请运行“导入模块 Az.Compute”。

“Get-Module -ListAvailable ”显示 Az.Compute 模块可用,但使用 Powershell 6 执行“import-module Az.Compute”命令时,没有导入任何内容。

小智 6

Install-Module -Name Az -AllowClobber -Scope CurrentUser
Run Code Online (Sandbox Code Playgroud)

运行该命令。重新启动 Powershell。import-module az.compute再次运行


SRo*_*Roy 1

我从事件查看器检查了 PowerShellCore/Operational 的日志,发现以下错误:

错误消息 = 无法加载文件或程序集“Microsoft.WindowsAzure.Storage,版本=9.3.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”。无法找到或加载特定文件。(HRESULT 异常:0x80131621)完全限定错误 ID = System.IO.FileLoadException、Microsoft.PowerShell.Commands.ImportModuleCommand

我已经安装了 Microsoft.WindowsAzure.Storage,最后调用了 powershell 脚本,并且成功执行了 Get-AZVM 命令。