Windows PowerShell Exit Codes, SSIS and the Environment.Exit Method

I was recently compiling a PowerShell script which would be integrated into a SSIS package, depending on the status of the script invocation this would return custom error codes to determine success or failure as part of the package. By default, I would generally use Try/Catch statements and provide and exit code. However, when invoking the script from a SSIS package this would not be returned correctly. The cause of this issue is due the powershell script being launced from the Windows Command Processor, when running natively from Windows PowerShell the exit code was returned successfully.

After a bit of research, I came across the Environment.Exit.Method which provides the functionality to terminate the process and provide the underlying operating system the custom exit code from my script.  Basically all this involved is replacing the previous method of providing an exit code with the above .NET method. For Example:

Exit("17");
[Environment]::Exit("17");

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s