【发布时间】: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