我正在尝试使用Windows 8.1上的Windows Azure PowerShell模块。 我已经下载并安装了Azure模块,并且在开始时我可以运行并使用“Windows Azure PowerShell”,它是一个只加载Azure的PS。 当我打开一个普通的PS窗口,并执行导入模块Azure失败:
import-module : The specified module 'Azure' was not loaded because no valid module file was found in any module directory.
我怀疑它与PowerShell版本或64 \ 32位版本有关。
任何人有这方面的经验?
Windows Azure SDK二进制文件和相关的PowerShell cmdlet都是32位的,这就是为什么“Windows Azure Powershell”快捷方式总是启动一个32位的shell。
您可以通过引用模块清单的文件系统path将Azure模块导入到现有的PowerShell会话中:
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
[更新]在最新的Azure中,使用
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1"
要单独通过名称访问模块,您需要将其位置包含在PSModulePath环境variables中(对于开发人员来说,这里是非常详细的):
$oldPSModulePath = [Environment]::GetEnvironmentVariable("PSModulePath") $azureModulePath = "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\" $newPSModulePath = $oldPSModulePath,$azureModulePath -join ";" [Environment]::SetEnvironmentVariable("PSModulePath",$newPSModulePath)
并为您的PowerShell的速记expression
$env:PSModulePath += ";C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\" Import-Module Azure # <-- Now you can do this!
您可以在PowerShellconfiguration文件中包含上述内容
如果您刚刚安装了Azure PowerShell SDK,请先重新启动计算机。 安装后需要重新启动,否则会引发此exception。
在Windows 10中,path已经改变。 看到下面的正确版本:
$oldPSModulePath = [Environment]::GetEnvironmentVariable("PSModulePath") $azureModulePath = "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement" $newPSModulePath = $oldPSModulePath,$azureModulePath -join ";"
对于Azure资源pipe理器模式模块(2015/09/11),请使用以下命令:
import-module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureResourceManager.psd1"
也可以尝试以pipe理员身份运行安装程序,方法是右键单击安装程序可执行文件并select以pipe理员身份运行。 一旦完成,重新启动。 你也可以像上面所说的那样运行导入,但是你不需要用较新的安装程序来完成。
根据您安装的SDK版本,您可能在path上有“Windows Azure”或“Azure”文件夹。
对于我的设置,我使用这个:
C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure
对于AzureRM 4.2.1(在这个答案的时候)。 它的模块path是不同的
$env:PSModulePath += ";C:\Program Files\WindowsPowerShell\Modules\" Import-module AzureRM
我在一台x64机器,windows 10操作系统上使用它。
您可能需要执行策略作为PowerShell在导入模块之前要求确认,这里是执行的策略链接 。