It's best to use Conditional Access based MFA when you have Azure AD Premium P1…
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:
- Windows PowerShell
- Windows PowerShell ISE
- Visual Studio Code
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 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y
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.
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.