Powershell – Import-Module Azure fails

azurepowershell

I am trying to work with Windows Azure PowerShell module on Windows 8.1. I have downloaded and installed the Azure module and in start I can run and use the "Windows Azure PowerShell" which is a PS that just loads Azure. When I open just a plain PS window and do Import-Module Azure it fails with:

import-module : The specified module 'Azure' was not loaded because no valid module file was found in any module directory.

I suspect that it have something to do with powershell versions or 64\32 bit versions.

Anyone has any experience with this?

Best Answer

The Windows Azure SDK binaries and pertaining PowerShell cmdlets are all 32-bit, which is why the "Windows Azure Powershell" shortcut always launches a 32-bit shell.

You can import the Azure module to an existing PowerShell session by referencing the filesystem path to the module manifest:

Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"

[Update] In latest Azure, use

Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1"

To access the module by name alone, you'll need to include its location in the PSModulePath environment variable (here in excruciating detail, for developers):

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

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

$newPSModulePath = $oldPSModulePath,$azureModulePath -join ";" 
[Environment]::SetEnvironmentVariable("PSModulePath",$newPSModulePath)

And a shorthand expression for your powershell

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

You could include the above in your PowerShell profile