Friday, February 10, 2017

First time connecting to Azure with Powershell - error

While I was following Microsoft's tutorial for connecting to Azure via Powershell I got an error message when trying to run this command: Login-AzureRmAccount


The error message was:


Login-AzureRmAccount : The 'Login-AzureRmAccount' command was found in the module 'AzureRM.Profile', but the module could not be loaded. For more information, run 'Import-Module AzureRM.Profile'. At line:1 char:1
+ Login-AzureRmAccount
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Login-AzureRmAccount:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule




In order to fix this issue I had to follow these steps:
  1. Open command prompt (cmd) as administrator
  2. type powershell Set-ExecutionPolicy RemoteSigned and press Enter
After this, the Login-AzureRmAccount command worked normally.

According to Microsoft, the Set-ExecutionPolicy command does the following (source):

The Set-ExecutionPolicy cmdlet enables you to determine which Windows PowerShell scripts (if any) will be allowed to run on your computer. Windows PowerShell has four different execution policies: 
Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned - Only scripts signed by a trusted publisher can be run.
RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted - No restrictions; all Windows PowerShell scripts can be run.