Friday, July 25, 2008

A Quick and Easy Progress Bar for Your Scripts.

I just wanted to post this really quickly because I hadn't heard of it.  Have you ever ended up with a script that was iterating through a large list without much feedback and wanted to let the user know that something really was going on in the background and please, please, don't hit Ctrl+C?

In the past I usually took the lazy way out, which is to just print another period every 100 iterations or so.  I just came across a cmdlet called Write-Progress that comes in handy here.

Check out the following code:

foreach ($index in (1..1000)) {
  Write-Progress -activity 'Destroying Earth' -status 'Obliterating...' -percentComplete ($index / 10)
}





No comments: