skip to Main Content

Connect to Azure AD with PowerShell

We like to connect to Azure AD with PowerShell because we want to retrieve Microsoft 365 MFA user status. Before we can do that, we have to install Microsoft Azure Active Directory Module. In this article, we will guide you step by step.

Install module MSOnline

To install the module MSOnline, you can use:

Start one of the above applications as administrator (high privileges). Run the command Install-Module MSOnline. Press Y and Enter.

PS C:\> Install-Module MSOnline

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

Do you get an error that it’s unable to install? Have a read at the article Unable to install NuGet provider for PowerShell.

Connect to Azure Active Directory

Run the Connect-MsolService cmdlet to initiate a connection with Azure Active Directory.

PS C:\> Connect-MsolService

After running the above cmdlet, the sign-in window shows up.

Connect to Azure AD with PowerShell

After connecting with Azure AD, you can run your PowerShell commands.

There is no Disconnect-MsolService cmdlet. What you can do is close the Windows PowerShell window.

Read more: Install Exchange Online PowerShell V2 »


In this article, you learned how to connect to Azure AD with PowerShell. Before you connect with MsolService (MSOnline), install the MSOnline module. Now you’re ready to run your commands and scripts.

Did you enjoy this article? You may also like Install and configure Azure AD Connect. Don’t forget to follow us and share this article.



ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 0 Comments

Leave a Reply

Your email address will not be published.