You can use the Write-Progress cmdlet to display progress status and percentage of process completed for a long running command or script. In normal cases you can use Write-Host command but if your script is going to run more time then you should use Write-Progress command to display the clear progress status.
The following command run the timer for 10 seconds and it update progress status for every second.
1..10 | ForEach { Start-Sleep -s 1 Write-Progress -Activity "Process Started : " -Status "Total items processed: $_" }
We can also display the progress bar by setting the parameter –PercentComplete
1..100 | ForEach { Start-Sleep -m 100 Write-Progress -Activity "Process Started" -Status "Total items processed: $_" -PercentComplete $_ }
We can also show the remaining time in seconds by setting the parameter –SecondsRemaining
1..10 | ForEach { Start-Sleep -s 1 Write-Progress -Activity "Process Started" -Status "Total items processed: $_" -SecondsRemaining (10-$_) }
Advertisement