First time here? Check out the site's "greatest hits" or read a post from the archives. Feel free to leave a comment or ask a question, and consider subscribing to the latest posts via RSS or e-mail. Thanks for visiting!
« Paper - Managing Large Scale System Depl... | Main | Expression Media Encoder - Preview Updat... »

PowerShell has a thousand nice features, but one of the nicer ones that I end up using all the time is the built in Write-Progress cmdlet. Shady the Intern came by today with a PowerShell script that printed dots to report progress, like:

Doing some stuff........................

I recommend he switch to Write-Progress. A nice feature of Write-Progress that I don't see used enough is the assigning of IDs to Activities, and then referencing those IDs as ParentIDs when writing out the progress of a Child Activity.

for ($i = 1; $i -le 10; $i++) 
{
  write-progress -id 1 -activity "Doing some stuff" -status "whatever" -percentComplete ($i*10);
   sleep 1; 
   for ($j = 1; $j -le 10; $j++)
   {
      write-progress -id 2 -parentId 1 -activity "Doing some child stuff" -status "yay" -percentComplete ($j*10)
      sleep 0.75
   }
}

PowerShell Progress

Here's a trivial example. Two for loops, each sleeping for a bit. The second for is a child of the first. Notice that ID of first loop is -activity 1 and the second references that activity via -parentActivity. This really adds, in my opinion, to the fit and finish of any script.



Tuesday, July 31, 2007 5:53:41 PM (Pacific Standard Time, UTC-08:00)
damn that's cool!

i was doing this in a much more long winded way.

one thing -- it'd be good to stick semi colons in your example, on the end of these two lines:

write-progress -id 2 -parentId 1 -activity "Doing some child stuff" -status "yay" -percentComplete ($j*10) ;
sleep 0.75;

cause otherwise when you copy and paste it all as one line, powershell thinks 'sleep' is a parameter to the write-progress command.

nifty trick, thanks!
lb



Tuesday, July 31, 2007 6:22:00 PM (Pacific Standard Time, UTC-08:00)
Yes, it's a cool feature; but implementing it in a custom PowerShell host is a pain in the neck! (doesn't help at all that the PowerShell hosting documentation is the suxorz, but still :))
Tuesday, July 31, 2007 8:11:06 PM (Pacific Standard Time, UTC-08:00)
I like your powershell color scheme/prompt.

Any chance you could post your settings?
Tuesday, July 31, 2007 8:48:35 PM (Pacific Standard Time, UTC-08:00)
Sure...I think it's the standard theme, but I'll check.
Wednesday, August 01, 2007 8:19:20 PM (Pacific Standard Time, UTC-08:00)
Although the series of dots, or o's is a simple method to present status, I have always found it very nice to see an updated % complete. OS/2, yes, OS/2, had a great status on the commandline ftp, where it would update the % complete as it upload/downloaded files. This was all text based, and provided me with more information than a series of dots does.

Is their perhaps a progress cmdlet that does this?
Comments are closed.

Contact

Sponsors

Hosting By

On this page...

Tags

Calendar

<September 2008>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

Archives

Google Ads