All scripts
Microsoft 365 562

Get-IntuneEnrollmentFailureReport

Summarizes device enrollment failures over a given period, grouped by failure reason, so a recurring enrollment problem gets fixed at the root cause instead of one ticket at a time.

Get-IntuneEnrollmentFailureReport.ps1
<#
.SYNOPSIS
    Summarizes Intune enrollment failures by reason.

.DESCRIPTION
    Pulls enrollment failure logs and groups them by failure reason, so
    a recurring enrollment problem (a specific profile, a specific OS
    version) gets fixed at the root cause instead of being handled one
    support ticket at a time.

.PARAMETER Days
    How many days back to look. Defaults to 30.

.EXAMPLE
    .\Get-IntuneEnrollmentFailureReport.ps1 -Days 14

.NOTES
    Requires Microsoft.Graph.DeviceManagement with an active
    Connect-MgGraph session.

.AUTHOR
    Shehryar Hassan
#>

param(
    [int]$Days = 30
)

$cutoff = (Get-Date).AddDays(-$Days)
$failures = Get-MgDeviceManagementDeviceEnrollmentFailure -All |
    Where-Object { $_.FailureDateTime -ge $cutoff }

$failures | Group-Object FailureCategory | Sort-Object Count -Descending |
    Select-Object Name, Count | Format-Table -AutoSize

Write-Host "$($failures.Count) enrollment failure(s) in the last $Days day(s)" -ForegroundColor Cyan

Read it before you run it, and test in a safe tenant first.