Getting Started with Microsoft Graph Powershell

Microsoft Graph is Microsoft’s new API to do everything in the M365 ecosystem. Along with normal API things like being able to interact using normal post/rest/etc requests, a Powershell module exists to streamline the connection from Powershell to Microsoft Graph.

PowerShell
# Installing the Microsoft Graph module (if you don't already have it)
Install-Module Microsoft.Graph -Scope CurrentUser

# Connecting to Microsoft Graph the easy way
Connect-Graph

Similar to the Exchange Online, SharePoint Online, and Azure AD Graph Powershell modules, the connect-graph command without any arguments will open a browser window to allow you to log in using your Microsoft credentials. Note that this uses delegated access so whatever access you have, is all the access Powershell will have.

RTFM

Microsoft Graph Powershell Documentation | Microsoft Learn

Microsoft Graph REST API v1.0 endpoint reference – Microsoft Graph v1.0 | Microsoft Learn

The Graph Explorer (below) is a really useful tool for looking at the capabilities of Microsoft Graph and accessing code snippets for multiple languages (including Powershell) to access the API.

Graph Explorer | Try Microsoft Graph APIs – Microsoft Graph

Useful Cmdlets/tools/etc

If you’re familiar with Azure AD Graph Powershell, converting to Microsoft Graph powershell should be pretty easy – aof the cmdlets are very similar.

PowerShell
# Get a list of all users in Azure AD
Get-MgUser -All

# Retrieve license details for a user
Get-MgUserLicenseDetails -UserID 'bob@example.com'

# Get your most urgent security messages from MS security centre
Get-MgSecurityAlert -Top 1 

# I'll add to this as I use it more and work out what's useful and what's not!

Leave a Reply

Your email address will not be published. Required fields are marked *