导入模块 Azure 失败

ita*_*ysk 19 powershell azure

我正在尝试在 Windows 8.1 上使用 Windows Azure PowerShell 模块。我已经下载并安装了 Azure 模块,一开始我可以运行和使用“Windows Azure PowerShell”,它是一个只加载 Azure 的 PS。当我只打开一个普通的 PS 窗口并执行 Import-Module Azure 时,它​​会失败:

import-module : The specified module 'Azure' was not loaded because no valid module file was found in any module directory.
Run Code Online (Sandbox Code Playgroud)

我怀疑它与 powershell 版本或 64\32 位版本有关。

任何人都有这方面的经验?

Mat*_*sen 19

Windows Azure SDK 二进制文件和相关的 PowerShell cmdlet 都是 32 位的,这就是“Windows Azure Powershell”快捷方式总是启动 32 位 shell 的原因。

您可以通过引用模块清单的文件系统路径将 Azure 模块导入现有的 PowerShell 会话:

Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
Run Code Online (Sandbox Code Playgroud)

[更新] 在最新的 Azure 中,使用

Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1"
Run Code Online (Sandbox Code Playgroud)

要仅通过名称访问模块,您需要将其位置包含在PSModulePath环境变量中(这里是对开发人员来说极其详细的细节):

$oldPSModulePath = [Environment]::GetEnvironmentVariable("PSModulePath")

$azureModulePath = "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\"

$newPSModulePath = $oldPSModulePath,$azureModulePath -join ";" 
[Environment]::SetEnvironmentVariable("PSModulePath",$newPSModulePath)
Run Code Online (Sandbox Code Playgroud)

以及你的 powershell 的速记表达式

$env:PSModulePath += ";C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\"
Import-Module Azure # <-- Now you can do this!
Run Code Online (Sandbox Code Playgroud)

您可以在 PowerShell 配置文件中包含上述内容

  • 谢谢,这也适用于 64 位 PS。有没有办法让快捷方式也能在 64 位 PS 中工作? (2认同)
  • 对我来说,我必须运行的命令是:Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1" (2认同)

Chr*_*ann 7

如果您刚刚安装了 Azure PowerShell SDK,请先重新启动计算机。安装后需要重启,否则会抛出此异常。