top of page

How to Connect to Microsoft Graph PowerShell



In this article you will learn how to connect to Microsoft Graph PowerShell.



What is Microsoft Graph PowerShell

The Microsoft Graph PowerShell includes a range of cmdlets designed to facilitate identity management at scale, from automating tasks to handling bulk user operations using Microsoft Enterprise ID.

As a replacement for the Azure AD PowerShell and MSOnline modules, Microsoft Graph PowerShell is the recommended tool for interfacing with Microsoft Enterprise ID.



Important: As per the update from Microsoft, the legacy licensing assignment PowerShell cmdlets (Set-AzureADUserLicense, Set-MsolUserLicense, -LicenseAssignment or -LicenseOptions parameters of New-MsolUser) and Azure AD Graph API (assignLicense) are retired. Also, Microsoft has plan to deprecate Azure AD, Azure AD-Preview, and MS Online PowerShell modules. Hence its time to move on with Microsoft Graph PowerShell commands to manage Microsoft 365 identities.



How to connect to Microsoft Graph PowerShell

The Microsoft Graph PowerShell SDK comes in two modules, Microsoft.Graph and Microsoft.Graph.Beta, that you’ll install separately. These modules call the Microsoft Graph v1.0 and Microsoft Graph beta endpoints, respectively. You can install the two modules on the same PowerShell version. Installing the main modules of the SDK, Microsoft.Graph and Microsoft.Graph.Beta, will install all 38 sub modules for each module.


Install Microsoft Graph PowerShell

Make sure the PowerShell script execution policy is set to remote signed or less restrictive. Open Windows PowerShell as Administrator, and run below PowerShell command:

PowerShellCopy

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

To install Microsoft Graph module, run below PowerShell commands:

PowerShellCopy

Install-Module Microsoft.Graph -Scope CurrentUser
Install-Module Microsoft.Graph.Beta

We recommend to install both modules on the same PowerShell window. Installing both modules will install all 38 sub modules for each module.


Connect Microsoft Graph PowerShell

After you have installed both modules in Windows PowerShell, connect to Microsoft Graph PowerShell using below PowerShell command:

PowerShellCopy

Connect-MgGraph -Scopes Directory.Read.All, Directory.ReadWrite.All, Organization.ReadWrite.All

Directory.Read.All, Directory.ReadWrite.All, Organization.ReadWrite.All is the highest privileged permission that allows you to manage all the tasks using Microsoft Graph PowerShell.

After you have connected to Microsoft Graph PowerShell, you can run PowerShell commands like, Get-MgUser, Update-MgUser, Update-MgUserLicenseDetail and so on.



Have a question or need help! Contact me 😊❤️

Comments


bottom of page