locked
PowerShell Install-SCOMAgent - Error Checking RRS feed

  • Question

  • I am having trouble doing error checking ont the Install-SCOMAgent cmdlet for the Operations Manager 2012 agent install.

    I get an error when I run it, but it doesn't register in a try catch block. Any ideas on how to get the errors?

    The install command looks like this:

    Install-SCOMAgent -PrimaryManagementServer $PrimaryManagementServer -Name $dnsHostName

    Thursday, June 14, 2012 10:16 AM

Answers

  • Most errors coming from cmdlets are "non-terminating" errors, which will not trigger a catch block.  If you want to force errors to bew "terminating" and trigger your error handling code, you have a couple of options:

    1. Set the magic variable $ErrorActionPreference = 'Stop'   This will force all errors to be terminating, and the effect is global.
    2. Set the common parameter -ErrorActionPreference 'Stop'  (or shorthand -ea 1) when calling a particular cmdlet.  The effect will only apply to that one cmdlet invocation.

    Try one of those appraoches, and your try/catch should start working.

    Thanks,
    -Lincoln

    • Marked as answer by Yog Li Thursday, June 28, 2012 7:59 AM
    Thursday, June 14, 2012 4:30 PM