How to Connect to Microsoft Graph PowerShell
In this article you will learn how to connect to Microsoft Graph PowerShell.
Table of Contents
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:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
To install Microsoft Graph module, run below PowerShell commands:
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:
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.
Conclusion
In this article you learnt how to use Microsoft Graph PowerShell. You might like our other article on Manage Office 365 users using Graph PowerShell and Manage users in Office 365 using PowerShell commands.
If you found this article helpful and informative, please share it within your community and share your feedback in the comments below.
Join us on YouTube for the latest videos on the Cloud technology and join our Newsletter for the early access of the articles and updates.
Happy Scripting!!