Blog/Intune

Safe automation for Intune: Graph, remediations, risk scores and AI guardrails

How to automate Intune without creating the next incident: least-privilege Graph permissions, polite API use, remediation scripts that cannot hurt you, a simple device risk score, vulnerability triage, and the confirmation gate every AI assistant needs.

IntuneAutomation
Applies toIntune, Microsoft Graph, Azure
AudienceAdmins and engineers who script Intune
PrincipleThe server decides, never the prompt
OutcomeFaster operations with a safety net
Good to know. The story in this guide is a composite of real migration projects. Company names, people and numbers are illustrative.
Device risk scores in the practice console
Device risk scores: one number per device, built from five signals, so the riskiest devices are fixed first.

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 registrationApplication permissionsUsed for
ReaderDeviceManagementManagedDevices.Read.All, DeviceManagementConfiguration.Read.All, DeviceManagementApps.Read.AllReports, health checks, questions
OperatorDeviceManagementManagedDevices.ReadWrite.AllDiagnostics and device updates
PrivilegedDeviceManagementManagedDevices.PrivilegedOperations.AllSync, restart, retire and wipe, with approval
Watch out. Keep write access to Conditional Access out of automation unless a named person approves each change. One wrong policy can lock everyone out, admins included.

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.

PowerShell
# 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 }
    }
  }
}
Tip. In tools that mix urgent actions and bulk reports, queue Graph calls by priority: an approved user action first, background reports last.

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 thatBecause
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 commandsHides what really runs
Contain plain-text passwordsEvery device gets a copy
Create local users, services, scheduled tasks or Run keysClassic persistence techniques
Load assemblies from memoryBypasses inspection
Create a remediation in the practice consoleLearn console · Intune admin center › Devices | Scripts and remediations

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.

SignalWeightFull points when
Compliance30%Not compliant (half when unknown)
Days since check-in25%More than 30 days
Encryption20%Not encrypted
OS version15%Below your oldest supported build
Configuration conflicts10%Several conflicts or errors
Good to know. Levels: 70 and above critical, 45 high, 20 medium, below that low. Review the critical list daily.
See risk scores in the practice consoleLearn console · Intune admin center › Device risk scores

Watch vulnerabilities that matter

Vulnerability watch with exploited CVEs
Vulnerability watch: actively exploited entries first, matched to the builds and apps in the tenant.

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.

SignalPoints
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 KEVat 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.

Open Vulnerability watch in the practice consoleLearn console · Intune admin center › Vulnerability watch

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.

AdminAssistantServerGraph1Asks to wipeLAP-01472Chooses wipe toolwith device ID3Destructive: issuetoken5 minutes, single use4Confirmsafter seeing details5Checks tokenvalid and unused6Wipe sentprivileged permission7Audit logwho, what, result
The token lives on the server. A second call without it does nothing.
  • 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

GuideIntune

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.

2 Dec 202619 min read
GuideIntune

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.

1 Dec 202616 min read
GuideIntune

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.

30 Nov 202615 min read