How to connect in Microsoft 365 with the Microsoft Graph

Based on Microsoft the AzureAD PowerShell Module and MSOnline PowerShell Module deprecated. 

So this is an oportunity to learn learn how to use Microsoft Graph PowerShell SDK to manage Microaoft 365 Tenant.

Today i will explain basic things like the prerequisites and how to connect in Microsoft365 Tenant with Microsoft Graph.

But i will continue with more articles for the Microsoft Graph and how to use it.

More details for the Depreciation of the Azure AD modules you can find in Important update: Deprecation of Azure AD PowerShell and MSOnline PowerShell modules

So let's start !!!



Before start the installation of the Microsoft Graph PowerShell SDK the following prerequisites are required

  • PowerShell 7 or later
  • .NET Framework 4.7.2 or later
  • Update PowerShellGet to the latest version
  • The Powershell script execution must be signed to remote signed or less restictive.

You can read the article How to update the PowerShell version on Windows that explain how to update your PowerShell version, install PowerShell 7 and update the .NET Framework. 


How to update PowerShellGet to the latest version and change the PowerShell script execution.

To update the PowerShellGet to the latest version run the following command

Install-Module PowerShellGet

Update PowerShell Get version


To change the PowerShell script execution run the following command

Set-ExecutionPolicy RemoteSigned

Set Powershell Execution policy



How to install Microsoft Graph

The next step before you will try to connect in Microsoft Graph is to install the Microsoft Graph.

Use the following command that will install Microsoft Graph only for my user

Install-Module microsoft.graph -Scope CurrentUser 

Install Microsoft Graph


If you would like to verify the installation use the following command

Get-InstalledModule microsoft.graph


How to connect in Microsoft365 with the  Microsoft Graph PowerShell

Now you are ready to connect in Microsoft Graph

We can use two types of authentication with Microsoft Graph.

  • Delegated Access = 
  • App-only access

Today we will use the Delegated Access. So use the following command. When you will press Enter it will ask to login with an account. Use your admin account of the M365 to connect.

Connect-MgGraph -Scopes "User.Read.All"

Connecting to Microsoft Graph


Now let's try a simple command to verify that we are logged in. Type the following command and you will get a list of all the users in your M365 Tenant . It's not the best view but we have verify that we are connected to Microsoft 365



I hope to find it useful and valuable.

Have a nice weekend !!!