Share via


suppressing the 'yellow' warning output?

Question

Tuesday, August 3, 2010 3:31 PM

Hello,

I know there are various ways to suppress the 'RED' error info, using -ErrorAction SilentlyContinue, or trap{}, etc... but for the first time I have run into a scenario where I get this 'YELLOW' warning output... how do I suppress it?

PS SQLSERVER:\sql> (gi wrongInstanceName -ea silentlyContinue) -eq $null
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on 'wds-smqs' failed with the following error: The RPC
server is unavailable. (Exception from HRESULT: 0x800706BA)
True

in example above, that output is yellow, the red error output is suppressed with -ea SilentlyContinue. Is there a way to also suppress this yellow warning output? I will be checking for and handling error cases in my script and I would rather not have this warning be output.

All replies (5)

Tuesday, August 3, 2010 4:02 PM ✅Answered

Read all about it at

 

http://stackoverflow.com/questions/369990/is-it-possible-to-customize-error-display-in-powershell

 

I like to use only black text on white background for everything

so I have this section in my profile.ps1

 

<##>

#

# use black on white for all text

#

$Host.Ui.RawUi.BackGroundColor = "White"

$Host.Ui.RawUi.ForeGroundColor = "Black"

$host.privatedata.ErrorForegroundColor = "Black"

$host.privatedata.ErrorBackgroundColor = "White"

$host.privatedata.WarningForegroundColor = "Black"

$host.privatedata.WarningBackgroundColor = "White"

$host.privatedata.DebugForegroundColor = "Black"

$host.privatedata.DebugBackgroundColor = "White"

$host.privatedata.VerboseForegroundColor = "Black"

$host.privatedata.VerboseBackgroundColor = "White"

$host.privatedata.ProgressForegroundColor = "Black"

$host.privatedata.ProgressBackgroundColor = "White"

<##>

 


Wednesday, August 4, 2010 9:18 AM ✅Answered | 6 votes

That's what the WarningAction parameter is for (v2):

 

gi wrongInstanceName -ea silentlyContinue -WarningAction silentlyContinue

Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar


Tuesday, August 3, 2010 4:14 PM

thanks again Larry!


Wednesday, August 4, 2010 2:43 PM

thanks Shay.

I need all my scripts to work on powershell v1, but that is good to know.


Saturday, July 30, 2016 10:13 AM

It's very simple. Use the -WarningAction option with a value of silentlycontinue.