【问题标题】:The 'Get-azVM' command was found in the module 'Az.Compute', but the module could not be loaded在模块“Az.Compute”中找到“Get-azVM”命令,但无法加载该模块
【发布时间】:2019-08-16 21:05:19
【问题描述】:

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

$VMExistanceCheck = 获取-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:“Get-azVM”命令 在模块“Az.Compute”中找到,但该模块无法 加载。有关更多信息,请运行“Import-Module Az.Compute”。 ---> System.Management.Automation.CommandNotFoundException:“Get-azVM” 在模块“Az.Compute”中找到命令,但模块无法 被加载。如需更多信息,请运行“Import-Module Az.Compute”。

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

【问题讨论】:

  • 您可以提供有关您遇到什么错误的更多详细信息?如果所有 Azure PowerShell 都无法执行?您在执行 Azure PowerShell 之前是否登录?
  • 你能发布完整的错误异常信息吗>
  • 您是否为本地机器设置了执行策略?
  • 是的。我已经设置为无限制了
  • 是不是只有Az.compute模块不能用?

标签: powershell azure-powershell az


【解决方案1】:
Install-Module -Name Az -AllowClobber -Scope CurrentUser

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

【讨论】:

    【解决方案2】:

    我从事件查看器查看了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 命令。

    【讨论】:

    • 此软件包已被弃用。见nuget.org/packages/WindowsAzure.Storage。它似乎已被多个包 Microsoft.Azure.Storage.Blob、Microsoft.Azure.Storage.File、Microsoft.Azure.Storage.Queue 和 Microsoft.Azure.Storage.Common 所取代。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-30
    相关资源
    最近更新 更多