Subscribe to Windows IT Pro
August 19, 2010 12:01 AM

Q. How can I suppress an error message in PowerShell?

Windows IT Pro
InstantDoc ID #125730
Rating: (0)

A. To look at other examples on the Internet, you'd think putting this at the top of your script would be the answer:

$ErrorActionPreference = "SilentlyContinue"

Don't do that. Sure, it'll suppress errors in your script—ALL of the errors, even helpful ones about syntax errors and so on. Instead, if you anticipate a cmdlet causing an error such as "file not found" or "could not connect" and you don't want to see the error or deal with it, use the -ErrorAction (or -EA) parameter of that cmdlet:

Get-WmiObject Win32_BIOS -computername localhost,not-online -EA SilentlyContinue

All cmdlets have an -EA parameter. It's part of the <CommonParameters> listed in every cmdlet's help.

 

Do you have a Windows PowerShell question? Why not submit it to Don? Post your question at www.windowsitpro.com/FAQs/FAQSubmittalForm.aspx and you might see your answer online! Find more PowerShell FAQs, articles, and other resources at windowsitpro.com/go/DonJonesPowerShell.

 

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.