Public/Test-AutopilotDevicePreparationReadiness.ps1

function Test-AutopilotDevicePreparationReadiness {
    <#
    .SYNOPSIS
        Evaluates local prerequisites visible to a device-preparation diagnostic session.
    #>

    [CmdletBinding()]
    param()

    $snapshot = Get-AutopilotDevicePreparationDiagnostic -EventLogLimit 1
    $runningOnWindows = [Environment]::OSVersion.Platform -eq [PlatformID]::Win32NT
    $majorVersion = 0
    $buildNumber = 0
    if ($snapshot.OperatingSystem.Version) {
        $majorVersion = ([version]$snapshot.OperatingSystem.Version).Major
    }
    if ($snapshot.OperatingSystem.BuildNumber) {
        [void][int]::TryParse($snapshot.OperatingSystem.BuildNumber.ToString(), [ref]$buildNumber)
    }

    $checks = @(
        [pscustomobject]@{
            Name    = 'Windows platform'
            Passed  = $runningOnWindows
            Detail  = if ($runningOnWindows) { 'Windows detected.' } else { 'This module is intended for Windows PowerShell.' }
        },
        [pscustomobject]@{
            Name    = 'Windows 11 or later'
            Passed  = $runningOnWindows -and $majorVersion -ge 10 -and $buildNumber -ge 22000
            Detail  = "OS version: $($snapshot.OperatingSystem.Version), build: $buildNumber"
        },
        [pscustomobject]@{
            Name    = 'Autopilot profile evidence'
            Passed  = -not [string]::IsNullOrWhiteSpace($snapshot.AutopilotProfile.CloudAssignedTenantId)
            Detail  = 'CloudAssignedTenantId is present when an Autopilot profile has been received.'
        },
        [pscustomobject]@{
            Name    = 'MDM enrollment evidence'
            Passed  = @($snapshot.Enrollment).Count -gt 0
            Detail  = "Enrollment records found: $(@($snapshot.Enrollment).Count)"
        }
    )

    [pscustomobject]@{
        PSTypeName = 'AutopilotPrepDiag.Readiness'
        Ready      = -not ($checks | Where-Object { -not $_.Passed })
        Checks     = $checks
        Snapshot   = $snapshot
    }
}