Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell: suppress Write-Progress output

I have a PowerShell script that calls a CmdLet which in turn reports its progress using Write-Progress, and I would like to hide the progress bar.
In is it possible to suppress or redirect the output of the Write-Progress CmdLet?

like image 488
Paolo Tedesco Avatar asked Dec 18 '09 14:12

Paolo Tedesco


People also ask

How do I suppress output in PowerShell?

To silence direct console output and discard all output, you can temporarily disable the internal PowerShell command Out-Default . This command is used privately to write directly to the console. Read more about Out-Default if you like.

What is PowerShell write-progress?

The Write-Progress cmdlet displays a progress bar in a PowerShell command window that depicts the status of a running command or script. You can select the indicators that the bar reflects and the text that appears above and below the progress bar.

How do I see the progress of a PowerShell script?

You can use the Write-Progress cmdlet to add a progress bar to any PowerShell script. Microsoft has provided a super simple script to show how this cmdlet works. The first line of the script sets up a loop. The loop starts with the $i variable set to 1 and each loop cycle increases the value of $i by 1 ($i++).

What is write-host command in PowerShell?

Starting in Windows PowerShell 5.0, Write-Host is a wrapper for Write-Information This allows you to use Write-Host to emit output to the information stream. This enables the capture or suppression of data written using Write-Host while preserving backwards compatibility.


1 Answers

Try setting this preference variable before calling the cmdlet that utilizes Write-Progress:

$ProgressPreference = 'SilentlyContinue'

You may want to revert back to 'Continue' afterwards.

like image 131
Keith Hill Avatar answered Sep 19 '22 13:09

Keith Hill