Site icon Think PowerShell

Hide PowerShell Progress Bars

PowerShell progress bar in action.

PowerShell progress bars don’t hurt anything, but they don’t always add value. Here’s how to hide them.

Progress Bars: What are they good for?

We are a species that craves to know the current state of things, and if we can’t be told that, at least we wan’t to know SOMETHING is happening. And because of this fundamental truth, we have spinning circles, hour glasses of old, and progress bars.

My favorite progress bars are the ones that aren’t actually progress bars at all because they don’t actually tell you far how you have progressed through a process. They are more like animated gifs of a bar filling to let you know that SOMETHING is happening, much like the spinning wheel.

PowerShell progress bars are at least true progress bars; the increase in percentage and the bar itself is tied back to underlying execution logic. So if you feel compelled to watch, at least you are seeing an actual progress status.

Hide a PowerShell progress bar with $ProgressPreference

If you aren’t really one to stare at your screen while your script is in action (if I am running something that will take a while, I use that as an excellent opportunity to get coffee; I’ll read the log file later :), or you’d rather not have a progress bar that overlays and obscures your terminal, there is a way to hide it using the Preference variable $ProgressPreference.

The default value for $ProgressPreference is Continue, which displays the progress bar for cmdlets that utilize it (including Write-Progress):

PS C:\Windows\system32> $ProgressPreference
Continue

Here are the alternative values:

Temporarily change $ProgressPreference

We don’t have to decide to hide progress bars for ever and always. Here is how we can hide a progress bar for a given command, and then revert to the default preference:

$OriginalPref = $ProgressPreference # Default is 'Continue'
$ProgressPreference = "SilentlyContinue"
Install-WindowsFeature -Name RSAT-DHCP
$ProgressPreference = $OriginalPref

And here is what that would look like:

Nothing to see here!

Making Progress Bars – the other side of the coin

I’m not a complete progress bar hater. I think there are some use cases where a progress bar is handy, and in my next post I will cover how to create your own.

Reference

Exit mobile version