Public/Test-DOConnectivity.ps1

function Test-DOConnectivity {
    <#
    .SYNOPSIS
        Checks whether this device can reach everything Delivery Optimization needs, and prints the results as a
        table with a one-line summary.
    .DESCRIPTION
        Test-DOConnectivity runs the same checks as Get-DOConnectivityMatrix and formats them for reading: one row
        per check (Check, Target, Port, Result, Ms, Detail) followed by a summary such as "42 checks: 1 fail, 2 warn."

        It tests the Microsoft endpoints in the module's endpoint list (Data\endpoints.json, rows named ep:<id>):
        DNS, TCP to the documented ports, a TLS handshake that judges the certificate's issuing chain, one HEAD request and
        one Range: bytes=0-0 request for a file this device downloaded, through the proxy DoSvc would use in the
        background. Wildcard endpoints are tested only on hosts the device has used or Microsoft documents; the rest
        are reported as not testable. It adds the local checks: download mode, peer port 7680 and its firewall
        rules, Teredo, the Connected Cache server, the proxy auto-config (PAC) script, and whether DoSvc is running.

        Results are pass, fail, warn, not-applicable or not-collected; a check that was not run is never shown as a
        pass. Endpoint probes take at most 4 seconds per stage, 8 hosts at a time and 40 seconds in total, and the
        results are never cached. The command is read-only. It throws when the check itself cannot run.
    .PARAMETER Anonymise
        Hash peer targets and internal names in the output, for a result you can share.
    .PARAMETER RangeProbeUri
        Optional extra object for the HTTP byte-range check, used only when its host is a Microsoft content host in
        Data\endpoints.json. Normally not needed: a file the device itself downloaded is used.
    .PARAMETER Json
        Return the results as one JSON string (the shape of connectivity[] in the inventory) instead of the table.
    .PARAMETER SkipConnectivityChecks
        Do not probe the network; every network check is reported as not-collected and only the local checks run.
    .EXAMPLE
        Test-DOConnectivity

        Prints the full table and the summary line. Run it from an elevated prompt for the complete picture, for
        example when peers or a Connected Cache server are not being used.
    .EXAMPLE
        (Test-DOConnectivity -Json | ConvertFrom-Json) | Where-Object result -eq 'fail' | Format-Table checkId, target, port, detail -Wrap

        Shows only the failed checks, read back from the JSON output. The parentheses make Windows PowerShell 5.1
        pass the rows on one at a time (its ConvertFrom-Json emits a JSON array as a single object).
    .EXAMPLE
        Test-DOConnectivity -Anonymise | Set-Content -Path C:\Temp\do-connectivity.txt -Encoding UTF8

        Saves the anonymised table as text to attach to a ticket for your network or proxy team.
    .EXAMPLE
        $json = Test-DOConnectivity -Json
        $failed = @(($json | ConvertFrom-Json) | Where-Object result -eq 'fail')
        if ($failed.Count -gt 0) { Write-Output ($failed.checkId -join ', '); exit 1 }
        Write-Output 'Delivery Optimization connectivity: no failed checks.'; exit 0

        An Intune remediation detection script that reports a device with a failed check as non-compliant (exit 1)
        and names the failing checks in its output. Run it in 64-bit PowerShell; as SYSTEM it can read everything.
        The script needs the module installed on the device.
    .INPUTS
        None. You cannot pipe objects to Test-DOConnectivity.
    .OUTPUTS
        System.String. The formatted table and the summary line, or with -Json one JSON string.
    .NOTES
        Runs on Windows. Elevation is not required; checks that need administrator rights are reported as
        not-collected. The probes reach only Microsoft endpoints, the configured Connected Cache server, peers the
        device already knows and the PAC scripts in force; nothing is sent to DoctorDO and nothing on the device is
        changed. Use Get-DOConnectivityMatrix for the rows as objects.
    .LINK
        https://www.doctor-do.com/get-started/
    .LINK
        about_DoctorDO.Collector
    .LINK
        Get-DOConnectivityMatrix
    .LINK
        https://learn.microsoft.com/windows/deployment/do/waas-delivery-optimization-faq
    #>

    [CmdletBinding()]
    [OutputType([string])]
    param(
        [switch] $Anonymise,
        [string] $RangeProbeUri,
        [switch] $Json,
        [switch] $SkipConnectivityChecks
    )
    $DDRun = Start-DDVerboseRun -Command 'Test-DOConnectivity'
    try {
        $results = @(Get-DOConnectivityMatrix -Anonymise:$Anonymise -RangeProbeUri $RangeProbeUri -SkipConnectivityChecks:$SkipConnectivityChecks)
    } catch {
        throw "Connectivity check could not run: $($_.Exception.Message)"
    }
    Stop-DDVerboseRun -Run $DDRun -Command 'Test-DOConnectivity' -Summary (Get-DDCountText -Rows $results -Noun 'checks')
    if ($Json) { return (ConvertTo-Json -InputObject $results -Depth 8) }
    $results | ForEach-Object {
        [pscustomobject]@{ Check = $_['checkId']; Target = $_['target']; Port = $_['port']; Result = $_['result']; Ms = $_['latencyMs']; Detail = $_['detail'] }
    } | Format-Table -AutoSize -Wrap | Out-String -Width 4096
    $bad = @($results | Where-Object { $_['result'] -eq 'fail' }).Count
    $warn = @($results | Where-Object { $_['result'] -eq 'warn' }).Count
    '{0} checks: {1} fail, {2} warn.' -f $results.Count, $bad, $warn
}