Connect to Azure using PowerShell

Do you want to know how to connect Azure portal using PowerShell? Check out this complete tutorial, here, I have explained different ways to connect to Azure using PowerShell.

We can use Azure PowerShell commands to manage resources in Azure.

Connect to Azure using PowerShell

There are two ways to connect to Azure from PowerShell.

  • By using the Install-Module AzureAD command
  • By installing Azure PowerShell on your local machine

We can also use the Azure Cloud Shell to connect to Azure using PowerShell.

Install-Module AzureAD PowerShell Module

To connect to Azure AD using PowerShell, you need first to install the AzureAD PowerShell module.

Make sure to open the PowerShell in admin mode, for this, Type “PowerShell” in the start menu -> Right-click on Windows PowerShell and choose “Run as administrator”

Before installing, you can also check if you have installed it or not by running the below command.

Get-Module -Listavailable

To install AzureAD on your local machine, run the below command in Windows PowerShell. Below is the PowerShell command.

Install-Module AzureAD

Once you run the command, this will install the Azure AD PowerShell module like the screenshot below:

connect to azure powershell

To know what Azure PowerShell modules are installed, run the below command.

Get-InstalledModule
or
Get-Module -Listavailable
powershell connect to azure

It is always good to install the latest version of Azure PowerShell, and you can run the below command to update the Azure PowerShell module.


Update-Module -Name AzureAD

Connect to AzureAD from PowerShell

Once you install the module, run the below PowerShell command to connect to Azure AD.

Connect-AzureAD

You can also run the below command

Connect-AzureAD -Credential (Get-Credential)

Once you run the above command, it will ask you for the username and password (Make sure the account has Azure AD administrator permission), and then it will connect to Azure AD.

Once you connect to Azure AD from PowerShell, you can check out a few examples below.

If you are not sure about the PowerShell commands available in Azure AD, run the below commands.

Get-Command -Module AzureAD

This will list down all the AzureAD PowerShell cmdlets.

Here is an example, Get all users from the Azure AD using PowerShell by running the below command.

Connect-AzureAD
Get-AzADUser

You can see it will display all the users from the Azure active directory.

connect azure powershell

This is how to connect PowerShell to Azure.

Install Azure PowerShell

Another way to connect to Azure PowerShell is to install Azure PowerShell on Windows using an MSI installer.

To work with Azure PowerShell, you should have:

Note: The PowerShell MSI installer works on having PowerShell versions 5.1 or higher. You can check the current PowerShell version by using the below command:

$PSVersionTable.PSVersion

If you are using the Widows, you will already have the PowerShell 5.1 version.

connect to azure using powershell

Now, you can download Azure PowerShell MSI package from GitHub.

Once downloaded, run the setup to install Microsoft Azure PowerShell. Click on Install like below:

connect to azure powershell

Now, you can see on the screen it is installing Azure PowerShell.