Wednesday, April 11, 2018

Showing a progress indicator in PowerShell

Some PowerShell cmdlets, like Update-Help, show a progress/status indicator near the top of the console while they're doing their work. Any PowerShell script can do that using the Write-Progress cmdlet. For example:

Write-Progress 'Doing a thing' -Status 'Initializing'

Later subsections of the same overarching operation use the same activity (first parameter) but different status:

Write-Progress 'Doing a thing' -Status 'Connecting'

The -PercentComplete switch produces a progress bar:

Write-Progress 'Doing a thing' -Status 'Doing' -PercentComplete 30

The -Completed switch indicates that the activity is finished, removing the progress tracker:

Write-Progress 'Doing a thing' -Completed

No comments:

Post a Comment