How to Connect to Your Microsoft 365 Tenant Using PowerShell
Microsoft 365 offers a set of Windows PowerShell modules to install, so that you can start managing your Microsoft 365 tenant right from your Windows machine. This article discusses two modules that help you connect to your Microsoft 365 tenant using PowerShell:
- Module 1: Connect with Microsoft Azure Active Directory Module for Windows PowerShell (MsolService module)
- Module 2: Connect with Azure Active Directory PowerShell for Graph Module (AzureAD module)
For those who like to watch and learn, check out the 4-minute video at the end of this article, which is a shortened version of this content.
Module 1: Connect with Microsoft Azure Active Directory Module for Windows PowerShell
To connect to your Microsoft 365 tenant using Microsoft Azure Active Directory Module, perform the following steps:
Open your Windows PowerShell terminal (ensure that you are running it as an administrator), and then run the following command:
Install-Module MSOnline
Figure 1 shows the message that you will get. To continue with the installation, either select:
Y [Yes]
or
A [Yes to All]

Once the installation is complete, connect to your Microsoft 365 tenant from Windows PowerShell by typing the following command:
Connect-MsolService
A Sign in to your account dialog box should pop up, prompting you to enter your Microsoft 365 admin credentials, as shown in Figure 2. To connect to your Microsoft 365 portal, provide your credentials.

Note: All Microsoft Azure Active Directory Module cmdlets begin with the prefix Msol. If you want to get a list of all the users available in your tenant, the command is:
Get-MsolUser
Module 2: Connect with Azure Active Directory PowerShell for Graph Module
To connect to your Microsoft 365 tenant using the AzureAD PowerShell module, perform the following steps:
Run the following command in your PowerShell terminal:
Install-Module -Name AzureAD
Figure 3 shows the message that you will get. To continue with the installation, either select:
Y [Yes]
or
A [Yes to All]

Import the installed module so that you can use it by running the following command:
Import-Module AzureAD
Now you are all set to connect. Run the following command to connect with your Microsoft 365 tenant:
Connect-AzureAD
A Sign in to your account dialog box should pop up, prompting you to enter your Microsoft 365 admin credentials. To connect to your Microsoft 365 portal, provide your credentials.

Note: Microsoft Azure Active Directory PowerShell for Graph Module cmdlets begin with the prefix AzureAD. If you want to get a list of all the users available in your tenant, the command is:
Get-AzureADUser
Possible Errors You Might Face
Here are examples of errors you might come across:
- Not running PowerShell as administrator: You might forget to run Windows PowerShell as an administrator. There are two options to fix this:
- Run this command: start-process powershell -verb runas
- Click Start, select PowerShell, and select Run As Administrator.
- Entering incorrect credentials: Ensure that you enter your Microsoft 365 credentials.
Conclusion
MsolService and AzureAD modules are popular PowerShell modules that help administrators connect to M365 tenants and manage them efficiently. Installing and using both are similar, with many administrators preferring AzureAD over the MsolService module. Still, certain management tasks can be run using only MsolService. It’s best to install and use both modules and switch between them depending on the task at hand.
For Those Who Like to Watch and Learn
The following video is a shortened version of this article. It explains how you can install MsolService and AzureAD PowerShell modules and use them to connect to your Microsoft 365 tenant.