If there’s a piece of software that grows fast and just keeps getting slower, it’s my PowerShell profile. It’s so useful to just cram another module load in there, or add another check script, or Update-Help, or a snippet of code to give a thought of the day. Mine is getting up above the ten second load time mark, and is rapidly approaching fifteen seconds.
Why? Well, I do a lot. I initialize my AWS credentials. I load my warmup scripts and F5 Load Balancer stuff. I make sure PSCX and xWebAdministration are available, and that I’m running at least PowerShell 4.0 (did I mention I ship my profile around from box to box? Yep). I also create a few aliases and read myself a line from my favourite song. I even spin up an asynchronous job to Update-Help, and I’m considering adding a few extra lines of code so I only do updates like that once a day. And code never gets removed, no way. What if I need it?
So it’s getting slow.
Well, I tweeted about this, and a mate tweeted back “you should implement a progress bar, so it at least seems like it’s loading quicker”.
Bloody good idea.
Luckily for me, Powershell supports progress bars natively. If you’ve done an Update-Help, you’ll have seen it. You’ll have also seen it if you’ve fired off an Invoke-WebRequest with an -outfile parameter pointed at a large-ish file. And what’s more, they’re pretty easy to use.
Here’s the basics
Write-Progress -Activity "doing stuff" -percentcomplete 25 -Status "doing a subtask of the stuff activity"
Your activity will appear in the First line. Your Status will appear in the second line. The pecentcomplete, obviously enough, defines how far along the progress bar is filled.
This is so absurdly easy, I’m surprised how few people use it. People still spit output to Write-Host (I certainly do), or at best Write-Verbose. Well, this doesn’t stop you doing that, but it’s a simple, neat way of showing progress. It’s good UX to let people know how much work has been done and how much remains and also it’s cool. Cool things are cool. You should totally use Write-Progress.