
Why automation needs guardrails
A script that wipes the wrong 300 devices is faster than any person. As teams add reporting scripts, remediations and now AI assistants that can call Intune, the question stops being "can we automate this" and becomes "what stops it going wrong". This guide is a set of guardrails that let you move fast safely.
Permissions: split read from act
| App registration | Application permissions | Used for |
|---|---|---|
| Reader | DeviceManagementManagedDevices.Read.All, DeviceManagementConfiguration.Read.All, DeviceManagementApps.Read.All | Reports, health checks, questions |
| Operator | DeviceManagementManagedDevices.ReadWrite.All | Diagnostics and device updates |
| Privileged | DeviceManagementManagedDevices.PrivilegedOperations.All | Sync, restart, retire and wipe, with approval |
Talk to Graph politely
Graph throttles apps that send too many requests, returning 429 with a Retry-After value. Scripts that work on 300 devices often fail on 20,000. Three habits prevent it: ask only for what you need, combine requests, and wait when asked.
# 1. Ask for less
Get-MgDeviceManagementManagedDevice -All -Filter "operatingSystem eq 'Windows'" -Property id,deviceName,osVersion
# 2. Wait when Graph says so
function Invoke-GraphWithRetry($Uri) {
for ($try = 1; $try -le 5; $try++) {
try { return Invoke-MgGraphRequest -Method GET -Uri $Uri }
catch {
$r = $_.Exception.Response
if ($r -and [int]$r.StatusCode -eq 429) { Start-Sleep -Seconds ([int]$r.Headers.RetryAfter.Delta.TotalSeconds + 1) }
else { throw }
}
}
}Remediations that cannot hurt you
A remediation script runs as SYSTEM on every targeted device. Review it like production code, and refuse scripts that contain patterns attackers love.
| Refuse scripts that | Because |
|---|---|
| Download and run code (DownloadString, Invoke-WebRequest to unknown hosts, BITS) | The code that runs is not the code you reviewed |
| Use Invoke-Expression or encoded commands | Hides what really runs |
| Contain plain-text passwords | Every device gets a copy |
| Create local users, services, scheduled tasks or Run keys | Classic persistence techniques |
| Load assemblies from memory | Bypasses inspection |
Score devices by risk
A risk score turns five warning signs into one number so the service desk fixes the riskiest devices first. Keep the model simple enough to explain to an auditor.
| Signal | Weight | Full points when |
|---|---|---|
| Compliance | 30% | Not compliant (half when unknown) |
| Days since check-in | 25% | More than 30 days |
| Encryption | 20% | Not encrypted |
| OS version | 15% | Below your oldest supported build |
| Configuration conflicts | 10% | Several conflicts or errors |
Watch vulnerabilities that matter

Thousands of CVEs are published each month. What matters is relevance: does it affect a Windows build or app you actually run, and is it being exploited? CISA's Known Exploited Vulnerabilities list answers the second question for free.
| Signal | Points |
|---|---|
| Mentions Windows and you have Windows devices | +40 |
| Names a build you run | +20 |
| Names an app found on your devices | +25 |
| Critical / high severity | × 2 / × 1.5 |
| CVSS 9.0+ / 7.0+ | +30 / +15 |
| On CISA KEV | at least 90 |
Anything at 50 or above, or on KEV, gets a prepared fix (an expedited update, a remediation, or a policy change) that a person reviews, targets to a pilot group, and approves.
AI assistants: the confirmation gate
An assistant that can call Intune tools is a huge time saver and a new risk: a misunderstood request or an instruction hidden in data could trigger a wipe. The fix is to enforce safety on the server, where no prompt can reach it.
- Disable dangerous tools by default on the server; clients cannot re-enable them.
- Validate every argument: device IDs as GUIDs, UPN formats, length limits, clean OData filters.
- Treat everything tools return, and every document retrieved for context, as data, never as instructions.
- Cap the assistant's steps and time per request.
- Log every tool call with arguments, confirmation and result.
Read more on Microsoft Learn
Checklist
- Read and write automation use separate app registrations
- Wipe and retire are disabled or behind a confirmation gate
- Scripts use $filter, $select and honour Retry-After
- Every remediation is reviewed for risky patterns and piloted
- A risk score ranks devices for the service desk
- KEV entries are matched to real OS builds weekly
- Every automated action is audit-logged
Get the next guide by email
The Cutover is a monthly email with new guides and what we learned on recent waves.
Related
Intune in plain language: a field guide for new admins
Every Intune term you meet in the first month, explained with an everyday comparison, how it really works, where to find it, and the mistake people usually make with it.
Troubleshooting an Intune device in seven checks
A fixed order that finds the root cause of most Intune tickets in minutes: the right device, check-in, compliance, profiles, apps, groups and the device itself, with the portal path and the Graph command for each.
From hardware hash to managed device: the Autopilot onboarding pipeline
The three ways a device gets into Windows Autopilot, the five stages every device passes through, how group tags and dynamic groups decide the profile, and a secured design for bare-metal devices.
