Getting started with Microsoft Graph for Intune
Microsoft Graph turns repetitive portal work into a few lines of PowerShell. The hard part is not the code, it is choosing the right permissions and understanding what the data actually represents.
By Simon Hoque
- Publication date
- Not yet published
- Estimated reading time
- 8 min read
Install the module and sign in
Install-Module Microsoft.Graph -Scope CurrentUser # Request the smallest scope that answers your questionConnect-MgGraph -Scopes "DeviceManagementManagedDevices.Read.All"Get-MgContext | Select-Object Account, TenantId, ScopesYour first device query
$devices = Get-MgDeviceManagementManagedDevice -All $devices | Where-Object { $_.OperatingSystem -eq "Windows" } | Select-Object DeviceName, ComplianceState, OsVersion, LastSyncDateTime | Sort-Object LastSyncDateTime -Descending | Select-Object -First 20v1.0 versus beta
A number of Intune properties only exist in the beta endpoint. Beta is useful for exploration but can change without notice, so pin production automation to v1.0 wherever the data exists there.
| Endpoint | Use for | Stability |
|---|---|---|
| v1.0 | Automation you depend on | Stable |
| beta | Exploration and new properties | May change |
Where to go next
Once reading works, wrap your query in a function, output structured objects rather than formatted text, and only then think about scheduling it as unattended automation with app-only authentication.
Found an error or have a better approach? Report it or suggest an improvement
Related articles
How to structure a new Microsoft Intune environment
A pragmatic naming, grouping, and assignment structure that keeps a fresh Intune tenant understandable as it grows.
- Publication date
- Not yet published
- Estimated reading time
- 9 min read
Troubleshooting Win32 app deployments
A repeatable order of investigation for Win32 apps that report failure, stay stuck at pending, or install without appearing installed.
- Publication date
- Not yet published
- Estimated reading time
- 7 min read