Using Get-Progress in PowerShell

Hello!

Despite the fact that PowerShell is a good automation tool, there are methods to writing to the console (the infamous Write-Host). But sometimes you may wish to display the progress of a particular task. In the past I have wanted to display the output of how many partitions had been processed or dropped from a list. And the best way to convey this is using Write-Progess.

Below are three examples of Write-Progress: the first is a super-simple example to give the context. The second goes slightly deeper in the fact that it gets the count of an object (in this case strings, but it could be anything) and uses that to display the progress. This is probably the most common way of using Write-Progress.

I really like Write-Progress because it looks neat but also helps give an idea of a timeframe a task will take to complete. If you want to give the duration for each activity you could use New-TimeSpan and write back to the progress bar. And this is exactly what is happening in the third example.

Leave a Reply

Your email address will not be published. Required fields are marked *