02 / PROCESS CONTROL AND REMOTING · LESSON 07

Pass arguments to simulated remote commands

Run parameterised script blocks against explicit computer contexts and return property snapshots.

12 min · learn at your pace

A transparent remoting adapter

Invoke-LabCommand is a teaching adapter. It checks the fixture computer's access state, then invokes your script block locally in the browser. It passes a Computer context as the first parameter, followed by your ArgumentList values. The context exposes ComputerName, OS, and Hardware.

This injected context is specific to the lab. Real Invoke-Command does not add this first argument. In a real remote script block, query the remote environment there, and use param(...) plus -ArgumentList for values from the caller.

Make dependencies explicit

Put param($Computer,$Minimum) at the start of the lab script block. Pass the threshold through ArgumentList. Avoid relying on a variable from the caller's scope. Local script blocks can see surrounding state in ways a real remote session cannot, so the adapter deliberately teaches explicit inputs.

Return simple data objects with ComputerName and the calculated values. Real remoting commonly returns deserialized property snapshots whose original methods are unavailable; simple types have exceptions. This lab does not simulate serialization, authentication, isolated runspaces, persistent sessions, $using:, or concurrent execution.

TCP reachability is only one layer

A listening WSMan port does not prove a command can run. Windows remoting uses WinRM, endpoint configuration, and permissions. PowerShell can also use SSH remoting, a distinct transport. This course models Ready, Offline, and AccessDenied outcomes without making a real WSMan connection or accepting credentials.

Go deeper

Read the official reference.

Try an example.ps1
Import-Module '/home/user/LabFleet.psm1' -Force
Invoke-LabCommand app01 -ArgumentList 2 -ScriptBlock { param($Computer,$Minimum) [pscustomobject]@{Name=$Computer.ComputerName;Minimum=$Minimum} }
YOUR TURN

Put it into practice.

Define Get-RemoteCapacity(ComputerName as a string array, MinimumFreeGiB). For each requested reachable computer, use the lab context and explicit threshold argument to return ComputerName, numeric FreeGiB, and boolean MeetsMinimum using an inclusive comparison. Do not run the function at definition time.

See an explained solution
One way to solve it.ps1
Import-Module '/home/user/LabFleet.psm1' -Force
function Get-RemoteCapacity {
    param([string[]]$ComputerName,[double]$MinimumFreeGiB)
    foreach($name in $ComputerName) {
        Invoke-LabCommand -ComputerName $name -ArgumentList $MinimumFreeGiB -ScriptBlock {
            param($Computer,$Minimum)
            $free=$Computer.OS.FreePhysicalMemory / 1MB
            [pscustomobject]@{ComputerName=$Computer.ComputerName;FreeGiB=$free;MeetsMinimum=($free -ge $Minimum)}
        }
    }
}

The caller passes the threshold explicitly and the script block reads the selected context. The returned objects are useful independent of how a future transport collects them.