Skip to content
ConsoleMonster
Cmdlet

Watch-Console

Module
ConsoleMonster

Runs a script block again and again and shows its latest output as a live view.

Syntax

Watch-Console
[-Count <Int32>]
[-Differences]
[-NoLive]
[-PollIntervalSeconds <Double>]
[-ReducedMotion]
[-ScriptBlock] <ScriptBlock>
[-Title <Object>]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Like watch: every -PollIntervalSeconds seconds the script block runs and its output replaces the previous one, shaped as Show-ConsoleTable and the other commands shape it (objects as a table, one dictionary as a record, text as it is). The heading shows the interval, -Title, the run number and the time. -Differences highlights the cells that changed since the previous run. A run that fails shows its error and the watch goes on. Warnings, errors and Write-Host text from the script block are shown under its output in the view (an error marks the run in the heading) instead of interrupting it. Ctrl+C ends the watch and the last frame stays in the scrollback; -Count ends it after that many runs. Without an interactive console (redirected output, CI, a job), the current view is printed once by default; an explicit finite -Count prints that many runs. Piped output is append-only; assigning the result to a variable at the prompt does not capture the live view, so pipe it instead.

Examples

Example 1

$watchConsoleOptions = @{
    ScriptBlock = { Get-Process | Select-Object -First 5 Name, Id, CPU }
    Count = 3
    PollIntervalSeconds = 1
}
Watch-Console @watchConsoleOptions

Watch a bounded process sample

Example 2

$watchConsoleOptions = @{
    ScriptBlock = { Get-Process -Id $PID | Select-Object Name, Id, CPU }
    Count = 3
    PollIntervalSeconds = 1
}
Watch-Console @watchConsoleOptions | Out-String

Capture repeated process snapshots as text

Example 3

$watchConsoleOptions = @{
    Differences = $true
    Title = 'Disk space'
    PollIntervalSeconds = 1
    Count = 3
    ScriptBlock = { Get-PSDrive -PSProvider FileSystem | Select-Object Name, Used, Free }
}
Watch-Console @watchConsoleOptions

Highlight changes in file-system drive space

Parameters

-Count Int32 optional
How many runs; zero follows interactively until Ctrl+C, or prints one snapshot without a user.
-Differences SwitchParameter optional
Highlights the cells that changed since the previous run.
-NoLive SwitchParameter optional
Disables live redraws and uses append-only output.
-PollIntervalSeconds Double optional
Seconds between runs (default 2).
-ReducedMotion SwitchParameter optional
Disables animation and limits live redraws to once a second without changing the layout. Accessible mode always enables reduced motion.
-ScriptBlock ScriptBlock requiredposition: 0
The script evaluated on each refresh to produce the next displayed value.
-Title Object optional
A title for the heading (markup); default the script block's text.

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.