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

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