Lessons Re-Learned: Error Handling with the Quest cmdlets

Prudent authors of Active Roles script activities and policy scripts will wrap key operations in a Try/Catch so that if the operation fails, the error can be gracefully handled. See the snippet below...

Try
{
New-QADUser -proxy -Name JSmith -Samaccountname JSmith -Description NewUser
}
Catch
{
Write-host "Uh oh, something went wrong."
}

I recently "re-learned" that the Quest cmdlets don't necessarily throw errors quite the same way as other cmdlets.

In my example above, the Catch would not necessarily be tripped if an Active Roles policy violation occurs. This can make troubleshooting challenging. I only discovered my mistake by looking at the Active Roles windows event log where I found the policy violation event!

Thus, as a bit of insurance, make sure you explicitly define what should happen in the case of an error:

Try
{
# ErrorAction switch ensures that an error will be trapped by the Catch
New-QADUser -ErrorAction stop -proxy -Name JSmith -Samaccountname JSmith -Description NewUser
}
Catch
{
Write-host "Uh oh, something went wrong."
}