19

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?

itaysk
  • 395
  • 2
  • 4
  • 9

8 Answers8

19

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

Blaise
  • 103
  • 4
Mathias R. Jessen
  • 24,907
  • 4
  • 62
  • 95
  • 2
    Thanks, that works also for 64 bit PS. Is there a way to make the shortcut work in 64 bit PS as well? – itaysk Jan 19 '14 at 10:12
  • 2
    For me command I had to run was: Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1" – Kai G Mar 09 '16 at 08:03
7

If you just installed the Azure PowerShell SDK, then restart the computer first. A restart is required after installation, otherwise this exception will be thrown.

Chris Pietschmann
  • 327
  • 1
  • 4
  • 10
1

For the Azure Resource Manager mode module (2015/09/11), use the following:

import-module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureResourceManager.psd1"
techraf
  • 4,163
  • 8
  • 27
  • 44
Jonathan Gao
  • 111
  • 1
1

In Windows 10, the path has changed. See correct version below:

$oldPSModulePath = [Environment]::GetEnvironmentVariable("PSModulePath")
$azureModulePath = "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement"
$newPSModulePath = $oldPSModulePath,$azureModulePath -join ";" 
Rahim
  • 11
  • 1
0

Also try running the installer as Administrator, by right clicking on the installer executable and choosing Run as Administrator. Once complete, reboot. You can also run the import as stated above but you should not need to do that with the newer installers.

0

Depending on the SDK version that you have installed, you may have a "Windows Azure" or just "Azure" folder on the path.

For my setup, I use this:

C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure
techraf
  • 4,163
  • 8
  • 27
  • 44
ozkary
  • 101
  • 2
0

For AzureRM 4.2.1 (at the time of this answer). Its Module Path is different in my case it is

$env:PSModulePath += ";C:\Program Files\WindowsPowerShell\Modules\"
Import-module AzureRM

I was using it on a x64 machine, windows 10 OS.

you might need Execution policies as powershell asks for confirmation before importing modules here is the link for execution oilicies.

Jawand Singh
  • 101
  • 2
0

I'm having the exact problem listed in the question. But I'm using Powershell Core. My symptom was slightly different (and highly confusing)

Import-Module : Could not load file or assembly 'System.Windows.Forms,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system
cannot find the file specified.

After a couple of days of wandering in the dark I found this issue on github for Powershell Core: https://github.com/PowerShell/PowerShell/issues/4090 and buried down in it deeply was a comment from an anonymous user. To wit: @LaurentPrat how are you importing AzureRM on linux? O_O you are supposed to load azurerm.netcore. While the discussion was about linux, the lightbulb moment realization was enough. There are new modules for azure powershell core.

My PS Startup profile now features this statement

if ($PSVersionTable.PSEdition -ieq "core") { 
    Import-Module AzureRM.Netcore 
}