Skip to content
ConsoleMonster
Cmdlet

Use-ConsoleProgress

Module
ConsoleMonster
Outputs
System.Object

Runs a script and shows its Write-Progress calls as an inline progress area.

Syntax

Use-ConsoleProgress
[-FramesPerSecond <Double>]
[-NoLive]
[-PrintFinalState]
[-ReducedMotion]
[-ScriptBlock] <ScriptBlock>
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

The script runs on the pipeline thread with the caller's variables. While it runs, Write-Progress (Activity, Status, CurrentOperation, PercentComplete, SecondsRemaining, Id and ParentId nesting, -Completed) is drawn as nested activities with bars, below the cursor and without the alternate screen; Write-Host and console output scroll above the area. When the script ends the final state stays (or disappears with -PrintFinalState:$false) and the script's output is returned. Calls the script makes directly are covered; commands inside other modules call their own Write-Progress, which PowerShell shows as usual. Inside the script, $ConsoleSession is this progress area's session, so Wait-ConsoleDashboard can capture or pause it. In jobs, remoting, the ISE and redirected output the script simply runs with $ConsoleSession set to null. If another runspace owns the terminal's progress area, the script also runs with PowerShell's native progress. Works on Windows PowerShell 5.1 and PowerShell 7.

Examples

Example 1

$progressOptions = @{
    ScriptBlock = {
        foreach ($i in 1..50) {
            Write-Progress -Activity 'Copying' -Status "File $i of 50" -PercentComplete ($i * 2)
            Start-Sleep -Milliseconds 50
        }
    }
}
Use-ConsoleProgress @progressOptions

An existing loop, unchanged

Example 2

Use-ConsoleProgress -PrintFinalState:$false {
    foreach ($server in 'web01', 'web02') {
        Write-Progress -Activity 'Inspect servers' -Status $server -PercentComplete 50
        [pscustomobject]@{ Server = $server; Result = 'Pass' }
    }
} | Show-ConsoleTable

Return server results and suppress the final progress area

Parameters

-FramesPerSecond Double optional
Redraw rate (default 15).
-NoLive SwitchParameter optional
Disables live redraws and uses append-only output.
-PrintFinalState SwitchParameter optional
Prints the final progress state in scrollback (default true); pass -PrintFinalState:$false to leave nothing behind.
-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 work to run while native Write-Progress calls update the inline progress area.

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.