AI will write your asset, license and patch-compliance reporting scripts in minutes — and it will confidently query the wrong Graph property or a stale RMM field. The working pattern: let AI draft the script, then reconcile its numbers against the vendor console before anyone downstream sees them.
Tier: Core · Workflow area: Scripting & automation · ~30 minutes
This playbook turns the monthly reporting grind — "how many licensed Visio seats are unused?", "which laptops are 60+ days behind on patches?" — into AI-drafted PowerShell against Microsoft Graph and your RMM's API, with a built-in verification step that keeps you from mailing management a number the console contradicts. (UC-29)
Set- or Remove- verbs has left its lane; see the scripting-safety module before running anything that mutates.Specify the report before you prompt. Write three lines: the question, the authoritative source, and the columns. Example: "Devices not patched in 60+ days; source of record is Intune (RMM is secondary); columns: deviceName, primaryUser, OS, lastPatchDate, daysBehind."
Have AI draft the Graph script with your constraints baked in.
Write a PowerShell script using the Microsoft Graph PowerShell SDK
(Connect-MgGraph, least-privilege scopes only — read scopes, nothing
admin) that reports Windows devices whose last successful patch
install is older than 60 days.
Requirements:
- Use Get-MgDeviceManagementManagedDevice; page through ALL results,
do not stop at the default page size
- Output: deviceName, userPrincipalName, operatingSystem,
complianceState, lastSyncDateTime, daysSinceSync
- Export to CSV with a date-stamped filename
- At the end, print a one-line summary: total devices, count over
threshold, and the exact Graph endpoint + filter used
Ask me clarifying questions before writing if any property you need
is ambiguous.
The last line matters: Graph property names drift between beta and v1.0, and a model that guesses silently is how lastSyncDateTime quietly becomes a proxy for "patched".
Read the draft for three specific failure modes before running it: paging (any Graph call without -All or explicit @odata.nextLink handling undercounts), property mismatch (does the property the script uses actually mean what your report claims?), and scope creep (reject any script requesting *.ReadWrite.* scopes for a report).
Run it and capture the summary line. Typical output:
Total managed Windows devices: 412
Devices with lastSyncDateTime > 60 days: 37
Source: GET /deviceManagement/managedDevices?$filter=operatingSystem eq 'Windows'
Export: patch-lag-2026-08-06.csv
Verify against console truth — every time, not just the first time. Open the Intune admin center (or your RMM dashboard), find the nearest built-in view — Reports > Device compliance, or the RMM's patch summary — and compare totals. You are checking two numbers: the population (412 managed Windows devices — does the console agree?) and the exception count (37 — is the console's stale-device count in the same neighborhood?). Small deltas usually mean timing or filter differences; write the explanation into the report footer. Large deltas mean the script is wrong — do not send.
Reconcile deltas with AI, not by hand. Paste both numbers and the script back:
My script reports 37 devices >60 days stale; the Intune console
compliance report shows 29 non-compliant. Here is the script: [paste].
List the most likely causes of this delta (filter differences,
property semantics, paging, co-managed devices, timing) and what to
check for each. Do not just pick one — rank all plausible causes.
Schedule it with the verification step attached. The script runs on a schedule; the console spot-check is a 90-second calendar task on report day. Add the footer line to every emitted report: "Verified against Intune console compliance view on 2026-08-06; delta of 8 explained by co-managed devices reporting via ConfigMgr." That sentence is what makes the number defensible in an audit or a license negotiation.
Get-MgSubscribedSku joined to user sign-in activity..Read. scopes. Verify in Entra, not in the script comments.Device and license exports contain user identities, hardware identifiers and org-structure detail — keep raw exports off public AI chat tools, redact userPrincipalNames before pasting samples into prompts, and prefer your tenant-approved assistant for anything containing real records.
AI makes the reporting script cheap; the console reconciliation makes the number true — automate the first, ritualize the second, and never send a figure whose delta from console truth you cannot explain in one sentence.