Sometimes, cmdlets automatically display a progress bar. Here is an example of such a progress bar:

$url = "http://www.powertheshell.com/reference/wmireference/root/cimv2/"
$page = Invoke-WebRequest -URI $url

Invoke-WebRequest retrieves the raw content for a web page, and if retrieving the content takes a while, a progress bar is shown.

Whenever you run a cmdlet that shows a progress bar, you can hide the progress bar by temporarily changing the $ProgressPreference variable. Just make sure you restore its original value or else, you permanently hide progress bars for the current PowerShell session:

$old = $ProgressPreference
$ProgressPreference = "SilentlyContinue"

$url = "http://www.powertheshell.com/reference/wmireference/root/cimv2/"
$page = Invoke-WebRequest -URI $url 

$ProgressPreference = $old

Rather than saving and restoring the original variable content, you can also use a script block scope:

& {
    $ProgressPreference = "SilentlyContinue"
    $url = "http://www.powertheshell.com/reference/wmireference/root/cimv2/"
    $page = Invoke-WebRequest -URI $url 
}

$ProgressPreference

As you see, the original variable value is automatically restored once the script block has finished.

Twitter This Tip! ReTweet this Tip!

Anonymous