Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Exit codes from shell and powershell

Created: 12 Oct 2013 | 3 comments

Hi

In our Workflow process we are using the component "Execute Process and wait" to run powershell.exe with arguments.

This is running successfully. The problem we are having is retrieving the %errorlevel% from the powershell completion. In our powershell scripts, we are exiting with specific errorcodes depending on what has been done. We want workflow to retrieve this value and then carry out specific workflow based on the return code.

When I manually run the powershell script from a windows command prompt and then echo %errorlevel%, upon completion I can see that powershell is correctly exiting with the required exitcode.

How do I get Workflow to retrieve the %errorlevel% this is not either "Standard Output" or "Standard Error".

I can't believe that workflow wouldn't be able to do this basic function. I must be using the incorrect component.

Thanks for you help

Cheers

Cherie

Operating Systems:

Comments 3 CommentsJump to latest comment

Rob Moore's picture

I don't believe you can get the %errorlevel% through this or any other componenet.

What you can do is modify the PS script to write the error level out to the console, which will be picked up by the standard output variable. You can then parse that text value and find the specific error code. It would be easier if you bracketd the error code with a specific words or symbols like <error>9009</error> or something similar so you can easily find and extract the data.

Rob

 

 

Nyobi's picture

Hi Rob

Yeah I had thought of this...My only concern with this approach is, it won't catch any errors that have slipped through errorhandling or that cause the powershell script to fail before this command is run.

Unless, I guess if workflow was configured to recognize a failure if there isn't an exitcode reported as well. This might be the catchall.

For an automation product, not capturing this data is a big oversight. We have in-house automated server deployment product(homegrown). I created the automation deployment code/scripts on the Windows side and in one of my server builds, I have over 150 commands for the installation and configuration for one application and this server has multiple applications and roles. Its very disappointing that our rather cheap product is out performing Altiris deployment and workflow.

I appreciate the feedback Rob :)

Cheers

C

 

 

 

ericg2's picture

Many people struggle with powershell return codes and i'm not even talking about workflow solution... Can you tell me how exactly you start your powershell script ?

Here is a way that I think should work

PowerShell.exe -Command "myscript.ps1'; Exit $LASTEXITCODE"