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

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? Find more PowerShell FAQs, articles, and other resources at windowsitpro.com/go/DonJonesPowerShell.