Watch-Console
Runs a script block again and again and shows its latest output as a live view.
Syntax
Watch-Console [-Count <Int32>] [-Differences] [-Interval <Double>] [-ScriptBlock] <ScriptBlock> [-Title <Object>] [<CommonParameters>]#All Parameter SetsDescription
Runs a script block again and again and shows its latest output as a live view.
Like watch: every -Interval seconds the script block runs and its output replaces the previous one, shaped as Format-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. Piped into another command (Out-File, Out-String), or without an interactive console (redirected output, CI, a job), every run is printed instead, so use -Count there; assigning the result to a variable at the prompt does not capture the live view, so pipe it instead.
Examples
EXAMPLE 1
Watch-Console { Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 } -Interval 2 -DifferencesWatch the busiest processes
EXAMPLE 2
Watch-Console { Get-Service Spooler } -Count 3 -Interval 5 | Out-File watch.logThree snapshots of a service, printed to a log
EXAMPLE 3
Watch-Console -Title 'Disk space' -Interval 10 -Differences { Get-Volume | Where-Object DriveLetter | Select-Object DriveLetter, FileSystemLabel, SizeRemaining, Size }Free space per drive with a title, changed cells highlighted
Parameters
- -Count Int32
- How many runs, or 0 (default) until Ctrl+C.
- -Differences SwitchParameter
- Highlights the cells that changed since the previous run.
- -Interval Double
- Seconds between runs (default 2).
- -ScriptBlock ScriptBlock
- The script block to run.
- -Title Object
- 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.