PowerShell connect to Microsoft 365 AD

PowerShell for Microsoft 365 enables Microsoft 365 server settings to be managed from command line. There are 2 versions of PowerShell module :

  1. AzureAD : Azure Active Directory PowerShell for Graph
  2. Msol : Microsoft Azure Active Directory Module for Windows PowerShell


What is the difference between AzureAD and Msol?

Msol : MSOnline module, with -Msol cmdlets, was the first Windows PowerShell Module for Active Directory. Microsoft refers to this module as version 1.0. MSOnline module provides certain functionality that is sitll not available with AzureAD module. Probably, MSOnline module will get deprecated when all the functionalities are made available with AzureAD.

AzureAD: Module is version 2.0. Microsoft recommends to use AzureAD module.


In this article, the steps to install both the Powershell modules are given.

Step 1 – Open Windows PowerShell in Administrator mode

Step 2 – Install AzureAD module in PowerShell

Use command : Install-Module-Name  AzureAD

This is obvious that you encounter an error as “PackageManagement\Install-PackageProvider : No match was found for the specified search criteria for the provider ‘NuGet’. the package provider requires ‘PackageManagement’ and ‘Provider’ tagas. Please check if the specified packages has the tags.”

In order to resolve TLS issue, use command :

All in One WordPress Hosting
HostGator $2.75 per month
24/7/365 Technical Support, Free Site Building Tools, 4500 Website Templates, Free Shopping Cart Software, Ideal for WordPress, 45 Day Money Back Guarantee
Starts at 30$ per month
All in One WordPress Hosting
High optimized WordPress hosting, secure firewall, HTTPS, Backup, hack-fix guarantee and many others at 30$ per month

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Then try to install AzureAD module, use command: Install-Module – Name AzureAD

when prompted to install modules from untrusted repository, press Y


Step 3 – Install MSOnline

Use Command: Install-Module MSOnline

when prompted to install modules from untrusted repository, press Y

Step 4 – Connect to Microsoft 365 using PowerShell

Use Command: $Credential = Get-Credential

In the Sign into your account dialog box, type your Microsoft 365 work or school account user name and password, and then select OK. If you’re using multi-factor authentication, follow the instructions to provide additional authentication information, such as a verification code.

After successful authentication, you can use the commands to connect to specific modules.

Connect-MsolService -Credential $Credential

Connect-AzureAD -Credential $Credential


Step 5 – Verify connection to Microsoft 365

In order to verify the AD connections are successful, you can use following commands

Get-MsolCompanyInformation     //view tenant information

Connect-AzureAD -Credential $Credential   //displays connecting account information


Must Read:

Menu Title