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

Q. How can I capture and examine any errors produced by a cmdlet?

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

A. Much like the -EA parameter, all cmdlets have a common parameter called -ErrorVariable (or -EV). Specify the name of a variable (which does not include the $ in front of the name), and any errors will be put into that variable. Here's an example:

Try {
  Gwmi Win32_BIOS -comp localhost,not-online -EA Stop -EV Err
} catch {
  Write-Host "Uh, oh $Err happened" -fore red -back white
}

To read about other common parameters, run

help about_common_parameters

in the shell.

 

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.