Suppress console output in PowerShell

PowershellOutputSuppress WarningsVerbosity

Powershell Problem Overview


I have a call to GPG in the following way in a PowerShell script:

$key = & 'gpg' --decrypt "secret.gpg" --quiet --no-verbose > $null

I don't want any output from GPG to be seen on the main console when I'm running the script.

Due to my noobness in PowerShell, I don't know how to do this. I searched Stack Overflow and googled for a way to do it, found a lot of ways to do it, but non of it worked.

The "> $null" for example has no effect. I found the --quiet --no-verbose options for GPG to put less output in the console, still it's not completely quiet, and I'm sure there is a way in PowerShell too.

Powershell Solutions


Solution 1 - Powershell

Try redirecting the output to [Out-Null][1]. Like so,

$key = & 'gpg' --decrypt "secret.gpg" --quiet --no-verbose | out-null

[1]: http://technet.microsoft.com/en-us/library/hh849716.aspx "Technet"

Solution 2 - Powershell

Try redirecting the output like this:

$key = & 'gpg' --decrypt "secret.gpg" --quiet --no-verbose >$null 2>&1

Solution 3 - Powershell

It is a duplicate of this question, with an answer that contains a time measurement of the different methods.

Conclusion: Use [void] or > $null.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDominik AntalView Question on Stackoverflow
Solution 1 - PowershellvonPryzView Answer on Stackoverflow
Solution 2 - PowershellDave SextonView Answer on Stackoverflow
Solution 3 - PowershellDirkView Answer on Stackoverflow