Implement monitoring and troubleshooting procedures to ensure diagnostic log collection works reliably across your managed devices.
Set up monitoring by creating a PowerShell script to check collection status across multiple devices. Save as MonitorDiagnosticCollection.ps1:
# Monitor diagnostic collection across devices
$TenantId = "your-tenant-id"
$ClientId = "your-app-id"
$ClientSecret = "your-client-secret"
# Get access token
$TokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
Client_Id = $ClientId
Client_Secret = $ClientSecret
}
$TokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token" -Method POST -Body $TokenBody
$Headers = @{Authorization = "Bearer $($TokenResponse.access_token)"}
# Get diagnostic collection requests
$DiagnosticRequests = Invoke-RestMethod -Uri "https://graph.microsoft.com/beta/deviceManagement/deviceLogCollectionRequests" -Headers $Headers
# Analyze results
$DiagnosticRequests.value | ForEach-Object {
Write-Output "Device: $($_.deviceName)"
Write-Output "Status: $($_.status)"
Write-Output "Requested: $($_.requestedDateTime)"
Write-Output "Size: $($_.sizeInKB) KB"
Write-Output "---"
}
Common troubleshooting scenarios and solutions:
Warning: If WNS is blocked by firewall, diagnostic collection will fail. Ensure these URLs are accessible: *.wns.windows.com, *.notify.windows.com, and *.push.apple.com for iOS devices.
Issue 1: Collection stuck in "Pending" status
# Force device sync to trigger collection
# Run on affected device or via Intune remote PowerShell
Get-ScheduledTask -TaskName "PushLaunch" | Start-ScheduledTask
Start-Process "C:\Windows\System32\deviceenroller.exe" -ArgumentList "/c /AutoEnrollMDM"
# Check WNS connectivity
Test-NetConnection -ComputerName "client.wns.windows.com" -Port 443
Issue 2: Custom logs not included
# Verify custom log placement
$LogPath = "C:\ProgramData\Microsoft\IntuneManagementExtension\Logs"
Get-ChildItem $LogPath -Filter "*.log" | Select-Object Name, Length, LastWriteTime
# Check for subdirectories (not supported)
Get-ChildItem $LogPath -Directory | ForEach-Object {
Write-Warning "Subdirectory found: $($_.Name) - Custom logs in subdirectories are not collected"
}
Issue 3: Large log files causing timeouts
# Check log file sizes and compress if needed
Get-ChildItem "C:\ProgramData\Microsoft\IntuneManagementExtension\Logs\*.log" |
Where-Object {$_.Length -gt 50MB} |
ForEach-Object {
Write-Warning "Large log file: $($_.Name) - $([math]::Round($_.Length/1MB,2)) MB"
# Optionally compress or truncate large files
$Content = Get-Content $_.FullName -Tail 10000
$Content | Out-File "$($_.FullName).truncated" -Encoding UTF8
}
Verification: Run the monitoring script weekly and check that diagnostic collections complete within 20 minutes. Failed collections should be investigated using the troubleshooting steps above.