June 6, 2009

Powershell Progress Bar

I needed to show a simple progress bar while I was running a long powershell script. It turns out that it is really simple to do and a snippet is found below:
#loop
for($it = 0; $it -lt $copy.length; $it++)
{
# Report progress
$percents = [System.Math]::Round(100 * $it / $copy.length)
Write-Progress -Activity "Working..." `
-PercentComplete $percents `
-CurrentOperation "$percents % complete" `
-Status "Please wait."
}
......
It displays a bunch of ooooooo as a progress bar. I really wish it had the bar style like an initial windows install, but it is not a big deal.

No comments:

Post a Comment