How to connect to Azure PowerShell (ARM / Azure AD)

Connecting to Azure PowerShell is a simple process that gives you a complete mix of administrative capabilities over your tenant, or your Azure AD deployment.

There are two ways you can connect to Azure services:

  • Connect to ARM using the Azure RM modules.
  • Connect to Azure AD using the Azure AD module.

How to connect to Azure ARM:

Connecting to ARM allows you to deploy and manage VMs via PowerShell cmdlets, manage storage, create Resource Groups and so on.

Azure PowerShell requires your connecting machine to be running PowerShell version 5.0. To check, run command $PSVersionTable.PSVersion and confirm the Major build is 5.

The next step installs the required Azure PowerShell modules from the PowerShell Gallery. Launch PowerShell as an administrator and run command Install-Module AzureRM.

You will be prompted to install NuGet if you have a version earlier than 2.8.5.201 or do not have it at all. Type y and press Enter.

To trust the PowerShell Gallery as a repository, type a and press Enter.

After a few moments numerous AzureRM modules will download and install on your machine. Once complete, issue command Import-Module AzureRM.

Now run command Connect-AzureRmAccount.

Enter credentials to manage your Azure tenant.

If successful, you will be returned some information from your tenant. Run a test command such as Get-AzureRmTenant and confirm that they issue correctly.

How to save credentials across PowerShell sessions:

You can save your Azure credentials using a feature called Azure Context Autosave which allows you to reuse credential information across future PowerShell sessions.

To save your credentials issue command Enable-AzureRmContextAutosave. As shown, context information will be saved under %AppData%\Roaming\Windows Azure PowerShell. When you next authenticate your credentials will be saved.

The next time you launch a new PowerShell session and connect to ARM, you will just be asked for the username.

You can view saved context by running command Get-AzureRmContext

If you want to remove a particular context issue command Remove-AzureRmContext -Name <name>

If you want to remove all saved context, run command Disconnect-AzureRmAccount

 Additional commands:

  • Get a list of AzureRm related modules – Get-Module Azure*
  • Get a list of cmdlets – Get-Command -Module Azure*
  • Update the Azure PowerShell module – Update-Module -Name AzureRM
  • Connect to an Azure China or Germany tenant – Connect-AzureRmAccount -Environment AzureChinaCloud for example.

How to connect to Azure AD:

You can use the Azure AD Module for PowerShell to create users, manage your domain and so on.

You must first download Azure AD PowerShell module from the PowerShell Gallery. Launch PowerShell as an administrator on a Windows 7 or Windows Server 2008 R2 or higher machine and run command Install-Module MSOnline

You will be asked if you want to trust the PowerShell Gallery as a repository. Type a and press Enter.

Now run command Connect-MsolService

Sign in with Azure AD administrator credentials.

Run command Import-Module MSOnline

You can now run a number of PowerShell cmdlets to manage your Azure AD environment.

⮩ Additional commands:

  • Get a list of cmdlets – Get-Command -Module MSOnline
  • Connect to an Azure China or Germany Azure AD – Connect-MsolService -AzureEnvironment AzureChinaCloud for example.

30 Comments

  • Anonymous

    March 26, 2019

    Why dont you start by how you dowload it

    Reply
  • Saddique

    April 10, 2019

    It is a very informative and user-friendly blog. It resolved my issues. Thank you

    Reply
  • saima

    June 28, 2019

    very detailed, I like it as a beginner

    Reply
  • Balajee

    September 17, 2019

    perfect place to connect quickly…thanks a tonne..

    Reply
  • Kichnifou

    October 1, 2019

    Thanks a lot, but if we want to have a script that connect us automatically without human intervention (= without Microsoft HMI connection), is it possible ?
    Maybe we can store our credentials in variables and use them to connect ?

    Reply
    • Ken

      December 1, 2019

      You can store your credentials in a variable by using the Get-Credential command e.g.
      $Office365Credentials = Get-Credential -Message ‘Please enter your MS Online administrator credentials.’
      Then when running the commands to connect, just add -Credential $Office365Credentials to the command. E.g. Connect-MsolService -Credential $Office365Credentials

      Reply
      • Anonymous

        January 31, 2020

        This does not seem to address the “without human intervention” part that the OP asked. Storing credentials in a file and loading them as part of the script execution works, but not with 2FA turned on. And app passwords didn’t work, either. I have not found a way to do this.

        Reply
  • Anonymous

    January 29, 2020

    Helped me in setting up my PowerShell.

    Reply
  • Alex

    April 2, 2020

    Wow. It’s people like you that make me wonder why anyone bothers sharing helpful information. Instead of just saying thanks for the useful information, you’re complaining that you can’t copy and paste. – You ungrateful cowardly moron !!

    Reply
  • sri

    April 29, 2020

    In the credentials page, the password page was blank. error.

    Reply
  • Pingback: SOLVED: VIDEO: How to connect to AzureAD AzureRM & AzureCLI using PowerShell – Up & Running Technologies, Tech How To's

  • Pingback: How to connect to AzureAD AzureRM & AzureCLI using PowerShell – Up & Running Technologies, Tech How To's [Video] - 360WiSE MEDiA

  • Thomas

    June 4, 2020

    Why am i unable to see the Microsoft Azure Active Directory Module for Window Powershell in control panel, add and remove program?

    Reply
  • Jeff

    June 17, 2020

    For those of you who run into the following error installing Azure ARM:

    WARNING: Unable to download from URI ‘https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409’ to ”.
    WARNING: Unable to download the list of available providers. Check your internet connection.
    Get-PackageProvider : Unable to find package provider ‘NuGet’. It may not be imported yet. Try ‘Get-PackageProvider
    -ListAvailable’.
    At line:1 char:1
    + Get-PackageProvider -Name:NuGet
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Microsoft.Power…PackageProvider:GetPackageProvider) [Get-PackageProvi
    der], Exception
    + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka
    geProvider

    Due to new cipher restrictions, you need to set the default SSL connection protocol in PS to TLS1.2 via:

    > [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    Then run the Install-Module AzureRM command and this should resolve the issue

    Reply
  • Pingback: azure ps

  • Anon

    November 4, 2020

    Great walkthrough , solved my problem!
    PS: had to change my role in Azure to Global Admin to successfuly connect to AzureRM

    Reply
  • Pingback: Azure Powershell Login - CaLoginGuide

  • Anonymous

    January 11, 2021

    Very clear guide, thank you!

    Reply
  • Pingback: azure ps – My Blog

  • Pingback: Azure Powershell Login » LoginCast.Com

  • Pingback: Azure Powershell Login - Login Teacher

  • Anonymous

    October 4, 2021

    Thanks. It helped 🙂

    Reply
    • Anonymous

      November 1, 2021

      This blog is Awesome and has helped me alot!

      Thanks for all your effort(s)!

      Reply
  • Anz

    February 9, 2022

    Is these are the same steps for how to connect powershell to cloud?

    Reply
  • Pingback: To Azure Powershell Logga In - SwedenSpace

  • Pingback: Login To Azure Via Powershell - logininfos.com

  • Aviandan

    January 27, 2023

    Is there any way to bypass Azure MFA and Connecting azure by providing only user id and password? Actually I want to automate some steps using PowerShell but MFA is restricting here. Any suggestion would be helpful.

    Reply
  • Pingback: Azure Powershell Login - ❤️ LoginWave

  • Pingback: Azure Powershell Login - ❤️ LoginWave - StreamWoop

Leave a Reply