1
Vote

Handled exceptions causing PostProcessingError

description

I'm using this to call back into the web service and add a user to a group (and still have AuthZ workflows trigger for approvals). When using the Import-FIMConfig an error is thrown with the text below.

While creating a new object, the web service reported the object is pending authorization. The import cannot continue until the object exists. Please approve the object and then replace all subsequent references to this object with its object id. Once the references are up to date, please resume the import by providing the output from this stream as input.

Handling that in the script was no big deal. I looped through all of the $Error objects and checked to see if they contain a snippet of that text. If so, I removed them ($Error.Remove($Error[$i)).

However, the workflow still throws an error and the annoying PostProcessingError. After debugging, I was able to see powershell.Streams.Error still contained the error info that I had handled and so the exception was thrown after the script executed.

I even added $Error.Clear() to the last line of the script without success.

Everything is executing properly, but I'd prefer for the request in the portal to show cleanly. Don't want to get into a situation ignoring errors and eventually find out something else broke within the script.

I'm not familiar with the powershell objects in C# so I'm not sure if the powershell.Streams.Error object is the same object I'm clearing in the script or if it holds all errors once they're thrown no matter what.


Thanks for you thoughts!

comments

bdesmondMVP wrote Dec 31, 2016 at 4:55 PM

I believe if you do something like this, you'll not get the error in the stream:

$myErrorVariable = $null

note there is no `$ before the variable name in the -ErrorVariable parameter

Import-FIMConfig ... -ErrorActionPreference SilentlyContinue -ErrorVariable myErrorVariable

You can then look at $myErrorVariable in your script and decide whether you want to bubble it up or not.