Table of Contents
PowerShell for Microsoft 365 enables you to manage your Microsoft 365 settings from the command line. To connect to PowerShell, just install the required software and then connect to your Microsoft 365 organization.
There are two versions of the PowerShell module that you can use to connect to Microsoft 365 and administer user accounts, groups, and licenses:
- Azure Active Directory PowerShell for Graph, whose cmdlets include AzureAD in their name.
- Microsoft Azure Active Directory Module for Windows PowerShell, whose cmdlets include Msol in their name
Requirements
- You should use PowerShell on Windows 10 or Windows 11. Be aware that you need to install .NET Framework 4.5 or later.
- An internet connection is required. TCP port 80 must be opened to connect from your local machine to the destination host.
- Access to Exchange Online PowerShell must be enabled for the current user (by default such access is enabled for administrators).
Connect to Microsoft 365 PowerShell (MSOL)
1. Right click on Windows icon then select Windows PowerShell Admin. In Windows 11, select Windows Terminal Admin instead of Windows PowerShell Admin.
2. Copy then paste all below commands into PowerShell window at once then hit Enter to install modules then connect to MSOnline PowerShell.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;
Install-PackageProvider -Name NuGet -Force;
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted;
Install-Module -Name MSOnline;
Connect-MsolService;
How do you know this worked
A quick test is to run an Azure Active Directory PowerShell cmdlet, for example, Get-MsolUser, and see the results.
PS C:\Users\mpnadmin> Get-MsolUser
UserPrincipalName DisplayName isLicensed
----------------- ----------- ----------
[email protected] Lidia Holloway True
[email protected] Diego Siciliani True
[email protected] Adele Vance True
[email protected] Alex Wilber True
[email protected] Henrietta Mueller True
[email protected] Grady Archie True
[email protected] Bon Guides True
Connect to Microsoft 365 PowerShell (AzureAD)
1. Open an elevated Windows PowerShell Command Prompt window (run Windows PowerShell as an administrator) then Run this command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;
Install-PackageProvider -Name NuGet -Force;
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted;
Install-Module -Name AzureAD;
Import-Module AzureAD;
Connect-AzureAD
2. After you connect, you can use the cmdlets for the Azure Active Directory PowerShell for Graph module.
Install two modules at once
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force;
Install-PackageProvider -Name NuGet -Force;
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted;
Install-Module -Name MSOnline;
Install-Module -Name AzureAD;
Import-Module AzureAD;