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

The 'Get-azVM' command was found in the module 'Az.Compute', but the module could not be loaded

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

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

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

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

使用运行空间从应用程序调用脚本时出现以下错误(System.Management.Automation,版本=6.1.0.0):

System.Management.Automation.RuntimeException: The 'Get-azVM' command was found in the module 'Az.Compute', but the module could not be loaded. For more information, run 'Import-Module Az.Compute'. ---> System.Management.Automation.CommandNotFoundException: The 'Get-azVM' command was found in the module 'Az.Compute', but the module could not be loaded. For more information, run 'Import-Module Az.Compute'.

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

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

错误消息=无法加载文件或程序集'Microsoft.WindowsAzure.Storage, Version=9.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'。无法找到或加载特定文件。 (HRESULT 异常:0x80131621) 完全限定错误 ID = System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

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

Install-Module -Name Az -AllowClobber -Scope CurrentUser

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