Microsoft Graph

Microsoft Graph (MS Graph) is the gateway to data and intelligence in Microsoft 365. It provides a unified programmability model that you can use to access the tremendous amount of data in Microsoft 365, Windows, and Enterprise Mobility + Security.

Graph Explorer

Graph Explorer is a developer tool that let’s you learn about Microsoft Graph APIs. Use Graph Explorer to try the APIs on the default sample tenant to explore capabilities.

Microsoft Graph Powershell

Installation

powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force

Import module

PowerShell import module function cannot import more than 4096 modules and Microsoft.Graph has 4096+ modules. Change the maximum before importing the module.

$MaximumVariableCount = 10000
$MaximumFunctionCount = 10000
Import-Module Microsoft.Graph

Authentication

Interactive authentication

A browser opens to authenticate to your tenant.

Connect-MgGraph

Device authentication

Navigate to a URL and enter a device code to authenticate.

Connect-MgGraph -UseDeviceAuthentication

Access token

Authenticate using your own access token.

Connect-MgGraph -AccessToken $AccessToken

Python

Installation

Enable long paths in Windows

See Maximum Path Length Limitation (Microsoft).

# Run as administrator
powershell
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

Install MS Graph SDK (BETA version)

pip install msgraph-beta-sdk

Azure CLI

ACCESS_TOKEN=<YOUR ACCESS TOKEN>
az rest --method GET --url "https://graph.microsoft.com/v1.0/me" --headers "Authorization=Bearer $ACCESS_TOKEN"