Scheduled Graph Data Exports
A registered Windows scheduled task that runs a suite of Microsoft Graph export scripts unattended, refreshing the CSV models behind the Power BI dashboards.
Overview
Cross-referencing Intune device data against Entra, or answering a one-off question about a group or a device, meant re-running the same handful of Graph queries by hand every time — resolve a device ID, pull a group's members, check what's assigned — and each one only stayed current for as long as someone remembered to run it.
Objective
Turn one-off Graph lookups into scripts that run unattended on a schedule, so the CSV exports behind the Power BI dashboards — and the ad-hoc questions in between — are current without someone remembering to kick them off by hand.
Approach
A single Windows Scheduled Task authenticates to Microsoft Graph as an app registration and runs a suite of purpose-built PowerShell scripts in sequence, each one answering one specific question — device state, group membership, assignment coverage — rather than one script trying to do everything. Every script follows the same shape: connect (or verify an existing connection), page through the Graph endpoint with @odata.nextLink until every record is in, shape the result into one flat object per row, and write a CSV. Setup and teardown scripts register and remove the scheduled task itself.
Solution
Get-EntraDeviceId.ps1 is the one most often run outside the schedule: point it at a CSV of Intune device IDs or device names, and it resolves each to its Entra device and object ID over Graph, cross-checking a UPN column when one's supplied to disambiguate devices sharing a generic name like "iPhone". An interactive menu picks which of twelve optional fields — platform, ownership, last activity, manufacturer, job title, department, office location and more — land in the output, so the same script answers a quick one-column lookup or a full device-and-user enrichment pass without maintaining two versions. It's on its fourth revision, each pass adding a case that came up in real use — a UTF-8 CSV that needed an ANSI fallback, duplicate device names with no UPN to break the tie.
The rest of the suite follows the same pattern for other questions — group membership exports, assignment coverage, sign-in history and office-location enrichment — each script narrow enough to read top to bottom in a minute, each one landing a CSV the scheduled task, or a person checking something right now, can pick up.
Technology
- PowerShell
- Microsoft Graph
- Task Scheduler
Outcome
Running on schedule today — the CSV exports behind the Power BI dashboards stay current without anyone remembering to kick off a script by hand, and Get-EntraDeviceId.ps1 gets reached for directly anytime a one-off ID lookup comes up outside the schedule.