Invoke-ConsoleDashboard
Runs a console dashboard live while a script does the work.
Syntax
Invoke-ConsoleDashboard
[-ArgumentList <Object[]>]
[-AutoRecord <Int32>]
[-Clock <SimulatedClock>]
[-Dashboard] <IWidget>
[-FramesPerSecond <Int32>]
[-ImportModule <String[]>]
[-Inline]
[-InputObject <Object>]
[-NoLive]
[-Parallel]
[-RecordPath <String>]
[-ScriptBlock] <ScriptBlock>
[-Summary <IWidget>]
[-ThrottleLimit <Int32>]
[-Transient]
[<CommonParameters>]#All Parameter SetsDescription
The script runs in a runspace the module owns (or, with -Parallel, once per input item on a runspace pool, started as items arrive and limited by -ThrottleLimit). Inside it, $ConsoleSession and the Update-ConsoleLane, Update-ConsolePhase, Write-ConsoleLogEntry and related cmdlets update the screen; Write-Host, Write-Warning, Write-Verbose, errors and Console.WriteLine go to the dashboard's log region instead of scribbling over the screen. The screen is redrawn at about 15 frames per second however many updates arrive. Ctrl+C stops the script and always restores the terminal; the dashboard then leaves the alternate screen and prints its final state (or -Summary). Script output is returned when the dashboard ends. In redirected or CI output the dashboard becomes append-only lines. Variables from the caller are not visible inside the script: pass them with -ArgumentList and a param() block.
Examples
Example 1
$d = New-ConsoleDashboard -Title 'Patch' -Content { New-ConsolePanel -Title 'Servers' -Content { New-ConsoleLanes }; New-ConsolePanel -Title 'Log' -Fill -Content { New-ConsoleLogRegion } }
'SRV1', 'SRV2', 'SRV3' | Invoke-ConsoleDashboard $d -Parallel -ThrottleLimit 3 {
param($Server)
Update-ConsoleLane -Key $Server -Status Running -Total 5
1..5 | ForEach-Object { Start-Sleep -Milliseconds 300; Update-ConsoleLane -Key $Server -Result Pass }
Write-Host "$Server patched"
Update-ConsoleLane -Key $Server -Complete
}Three servers processed in parallel, three at a time
Parameters
- -ArgumentList Object[]
- Arguments passed to the script (after the input item with -Parallel).
- -AutoRecord Int32
- Records the run automatically to the local ConsoleMonster\Recordings folder and keeps only this many recent runs (within 50 MB together), for Show-ConsoleReplay. Ignored with -RecordPath.
- -Clock SimulatedClock
- A run clock (New-ConsoleSimulatedClock) for the header clock, the summary bar's times and log times, instead of real time. Pass it to the script with -ArgumentList to move it forward there.
- -Dashboard IWidget
- The dashboard from New-ConsoleDashboard (or any widget tree).
- -FramesPerSecond Int32
- Redraw rate (default 15).
- -ImportModule String[]
- Modules to import into the dashboard runspaces.
- -Inline SwitchParameter
- Draws the dashboard inline, below the cursor, instead of on the alternate screen: output and log lines scroll above it and the final state stays in the scrollback.
- -InputObject Object
- Items processed with -Parallel; each item is the script's first argument.
- -NoLive SwitchParameter
- Disables live redraws and uses append-only output.
- -Parallel SwitchParameter
- Run the script once per input item on a runspace pool.
- -RecordPath String
- Record every update as JSON lines for Show-ConsoleReplay -PlaybackMode Automatic.
- -ScriptBlock ScriptBlock
- The work to run while the dashboard is live.
- -Summary IWidget
- A widget printed to scrollback after the dashboard ends (default: the dashboard's final state).
- -ThrottleLimit Int32
- Maximum concurrent runspaces with -Parallel (default 4).
- -Transient SwitchParameter
- Leaves nothing behind when the dashboard ends (no final state in the scrollback).
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.