๐ฑ Recipe ยท Intune & Device Management
Bulk Trigger Intune Device Diagnostics Collection
Remotely collect diagnostic logs from all managed devices in Microsoft Intune using a single bulk action
Complexity
Intermediate
Impact
bulk-operation + device-management + troubleshooting + privileged-action
Context
Why This Matters
When troubleshooting fleet-wide issues โ a failing configuration profile, a compliance regression after an OS update, or a suspected MDM agent problem โ IT admins often need diagnostic logs from many devices at once. Intune exposes a per-device createDeviceLogCollectionRequest action that triggers the MDM agent to upload a log bundle to Intune, where it can be downloaded as a ZIP for analysis.
The Intune admin center only lets you trigger this action one device at a time, which is impractical for tenants with hundreds or thousands of devices. This recipe shows how to fan the action out across your entire managed device estate (or a filtered subset) using Microsoft Graph.
When to run this recipe
- A widespread issue is reported and you need diagnostic data from many devices for root-cause analysis
- You are preparing a Microsoft support case and need logs from a representative device sample
- You want to verify MDM agent health across the fleet after a major configuration change
- A compliance policy is failing unexpectedly on multiple devices
Expected Outcomes
After completing this recipe you will have:
- A log collection request queued against every targeted managed device in Intune
- A CSV/JSON record of which devices were successfully requested, skipped, or failed
- Diagnostic log ZIP bundles downloadable from the Intune admin center once devices check in (Windows / macOS / iOS / Android supported; coverage varies by platform)
- A repeatable script you can rerun against filtered device sets (by OS, compliance state, group membership, etc.)
Devices will upload logs on their next MDM check-in. For Windows, this typically happens within 8 hours; you can shorten this by also triggering a sync action.
Risks & Considerations
Operational risks
- Network load on endpoints: Each device uploads a multi-MB diagnostic bundle. Running this against thousands of devices simultaneously can produce a noticeable spike in outbound traffic from client networks.
- Platform coverage is uneven:
createDeviceLogCollectionRequestis fully supported on Windows 10/11 co-managed and MDM-enrolled devices. macOS, iOS, and Android support is limited or requires the device to be corporate-owned / supervised. Unsupported devices will return errors โ expect these and do not treat them as failures. - Offline devices: The request queues until the device next checks in. Devices that never check in (retired, lost) will show a pending request indefinitely.
- Throttling: Microsoft Graph enforces per-tenant and per-app throttling. For large fleets, pace the requests (batches of 20 with a short delay) to avoid HTTP 429 responses.
Privacy and compliance
- Diagnostic logs may contain user names, device names, installed app inventory, and event log excerpts. Treat the downloaded bundles as confidential and store them according to your data retention policy.
- In jurisdictions with works councils or strict privacy controls (e.g. Germany, France), confirm that bulk log collection is permitted before running.
- Do not leave collected logs in admin mailboxes or shared drives indefinitely โ purge after the investigation is complete.
What NOT to do
- Do not run this against your entire fleet as a routine health check โ it is an on-demand troubleshooting tool.
- Do not skip the dry-run / targeting review step. A typo in a filter can target the wrong population.
Required Permissions
| Permission | Why It's Needed |
|---|---|
| DeviceManagementManagedDevices.Read.All | Required to enumerate managed devices and read their metadata (OS, enrollment state) for targeting. |
| DeviceManagementManagedDevices.PrivilegedOperations.All | Required to invoke the createDeviceLogCollectionRequest action โ this is a privileged device management operation. |
The fastest way to get this done: just ask Dex. Copy the prompt below and paste it into your Dex conversation.
For IT Admins
Paste into Dex Pro
The Intune admin center does not support a true bulk "collect diagnostics" action โ you must trigger it on each device individually. Use this path for a small number of devices (under ~20); for larger fleets, use the Graph API or PowerShell approach.
Per-device procedure
- Sign in to the Microsoft Intune admin center with an account that has the Intune Administrator or Help Desk Operator role.
- Navigate to .
- Use the filter bar to narrow the list (e.g., OS = Windows, Compliance = Not compliant) and locate the target device.
- Click the device name to open its overview blade.
- In the action bar at the top, click Collect diagnostics. (On Windows this appears as Collect diagnostics; on macOS it may be labeled Collect logs.)
- Confirm the action in the prompt. The request is queued and the device will upload logs on its next check-in.
- To retrieve the logs, wait for the request status to change to Complete, then open and click Download on the relevant entry.
Tracking bulk requests
After triggering many requests via script/API, you can review their status centrally at . This view shows all pending and completed collection requests across the tenant, with download links for completed bundles.
Microsoft Graph exposes two endpoints you will use: one to enumerate devices, one to trigger the collection.
Step 1 โ Enumerate target devices
GET https://graph.microsoft.com/beta/deviceManagement/managedDevices?$select=id,deviceName,operatingSystem,complianceState&$filter=operatingSystem eq 'Windows'Use $filter to narrow the targeting (by OS, compliance state, enrollment type, etc.) and $select to keep payloads small. The endpoint is paginated โ follow @odata.nextLink until it is absent.
Sample response:
{
"value": [
{
"id": "9f420691-1c67-4b46-b154-0e1b1342f4c4",
"deviceName": "DESKTOP-EXOTIC-891",
"operatingSystem": "Windows",
"complianceState": "nonCompliant"
}
],
"@odata.nextLink": "https://graph.microsoft.com/beta/deviceManagement/managedDevices?$skiptoken=..."
}Step 2 โ Trigger diagnostics collection for each device
POST https://graph.microsoft.com/beta/deviceManagement/managedDevices/{managedDeviceId}/createDeviceLogCollectionRequest
Content-Type: application/json
{
"templateType": "predefined"
}Response: HTTP 200 OK with an empty body on success. A 400 typically means the device platform does not support the action; a 404 means the device ID is stale.
Step 3 โ Check request status (optional)
GET https://graph.microsoft.com/beta/deviceManagement/managedDevices/{managedDeviceId}/logCollectionRequestsReturns an array of past and pending requests with status (pending, completed, failed) and, for completed requests, a SAS URL to download the log bundle.
Throttling guidance
- Use concurrency of no more than 10 parallel POSTs.
- Retry on HTTP 429 using the
Retry-Afterheader. - For fleets > 500 devices, expect the full rollout to take several minutes.
The script below uses the Microsoft.Graph.Beta.DeviceManagement module to enumerate devices, optionally filter them, and fan out createDeviceLogCollectionRequest calls in batches with throttle handling.
Prerequisites
- PowerShell 7+ (recommended) or Windows PowerShell 5.1
- Microsoft Graph PowerShell SDK:
Install-Module Microsoft.Graph.Beta -Scope CurrentUser - A signed-in account with Intune Administrator or equivalent role
Running the script
- Save the script (below) as
Invoke-IntuneBulkDiagnostics.ps1. - Connect to Graph:
Connect-MgGraph -Scopes "DeviceManagementManagedDevices.PrivilegedOperations.All","DeviceManagementManagedDevices.Read.All" - Run with a filter:
.\Invoke-IntuneBulkDiagnostics.ps1 -OperatingSystem Windows -WhatIfto preview. - Remove
-WhatIfto actually trigger the collection.
What the script does
- Enumerates managed devices with optional filters (OS, compliance state, device name pattern)
- Shows a summary table and prompts for confirmation before firing POSTs
- Runs the POSTs with a configurable concurrency cap and automatic retry on HTTP 429
- Writes a CSV log of successes and failures to
.\diagnostics-bulk-result-YYYYMMDD-HHmm.csv
After the script completes, monitor progress at and download the log bundles from there as each device checks in.
Next steps