none
suppressing the 'yellow' warning output? RRS feed

  • Question

  • 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.

    Tuesday, August 3, 2010 3:31 PM

Answers

  • 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
    • Marked as answer by c0pe Wednesday, August 4, 2010 2:42 PM
    Wednesday, August 4, 2010 9:18 AM
    Moderator
  • Read all about it at
     
     
    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"
    <##>
     
    • Marked as answer by c0pe Tuesday, August 3, 2010 4:12 PM
    Tuesday, August 3, 2010 4:02 PM

All replies

  • Read all about it at
     
     
    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"
    <##>
     
    • Marked as answer by c0pe Tuesday, August 3, 2010 4:12 PM
    Tuesday, August 3, 2010 4:02 PM
  • thanks again Larry!
    Tuesday, August 3, 2010 4:14 PM
  • 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
    • Marked as answer by c0pe Wednesday, August 4, 2010 2:42 PM
    Wednesday, August 4, 2010 9:18 AM
    Moderator
  • thanks Shay.

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

    Wednesday, August 4, 2010 2:43 PM
  • It's very simple. Use the -WarningAction option with a value of silentlycontinue.

    Saturday, July 30, 2016 10:13 AM