02 / PROCESS CONTROL AND REMOTING · LESSON 08

Keep failures in the fleet report

Collect successful remote results and preserve offline, denied, and unknown-computer outcomes.

12 min · learn at your pace

Missing rows hide missing coverage

A fleet report containing only successful computers looks complete until someone compares it with the requested scope. Return one outcome for every input computer, including failures. Keep the identity on both success and error records.

The lab throws labelled failures: Offline, AccessDenied, and UnknownComputer. Use a try/catch inside the loop so one inaccessible host does not stop collection for the rest. -ErrorAction Stop expresses the intent to catch errors from commands that would otherwise emit non-terminating errors; the lab's explicit throws are already terminating.

Separate status from measurements

A failure record should have Build set to $null, not zero or a guessed OS version. Preserve a useful Detail message and a stable Status code. Treat an inaccessible computer as unknown coverage, not as a healthy system or an empty inventory.

This task derives Status from the lab's documented colon-prefixed error message. Real collectors should prefer structured error categories or error IDs where available. Do not build a universal WinRM error classifier from these fictional strings.

Recover per computer

The tests request failures before and between successful hosts, then request an empty scope. An empty request returns no records. An unknown computer returns an explicit failure row. No credentials, endpoint configuration, network probes, or actual remote commands are involved; you are building the reporting contract that can later surround a genuine collector.

Go deeper

Read the official reference.

Try an example.ps1
Import-Module '/home/user/LabFleet.psm1' -Force
try { Invoke-LabCommand offline01 -ScriptBlock { param($Computer) $Computer.ComputerName } } catch { $_.Exception.Message }
YOUR TURN

Put it into practice.

Define Get-RemoteOsReport(ComputerName as a string array). Return one object per requested host, preserving order, with ComputerName, Status, Build, and Detail. Ready hosts have numeric Build 20348 and Detail Collected. Failed hosts have Status Offline, AccessDenied, or UnknownComputer from the lab error, null Build, and the error message in Detail. Continue after failures.

See an explained solution
One way to solve it.ps1
Import-Module '/home/user/LabFleet.psm1' -Force
function Get-RemoteOsReport {
    param([string[]]$ComputerName)
    foreach($name in $ComputerName) {
        try {
            Invoke-LabCommand $name -ScriptBlock {
                param($Computer)
                [pscustomobject]@{ComputerName=$Computer.ComputerName;Status='Ready';Build=[int]$Computer.OS.BuildNumber;Detail='Collected'}
            } -ErrorAction Stop
        } catch {
            $message=$_.Exception.Message
            [pscustomobject]@{ComputerName=$name;Status=($message -split ':',2)[0];Build=$null;Detail=$message}
        }
    }
}

Per-computer error handling preserves both successful measurements and the collection gaps. A null measurement remains distinguishable from a measured zero.