Page 1 of 1

PSS 2014 How to return an exit code from Windows Package

Posted: Tue Jun 24, 2014 3:04 am
by mkedaj
Hi,

I want to package a script as Windows exe.
My sample code:
PowerShell Code
Double-click the code block to select all.
$script:ExitCode = 2
$global:ExitCode = 3
Packaged with "V3 Host (Command line) x64" :
PowerShell Code
Double-click the code block to select all.
PS C:\Test> .\TestExit.exe;$?;$LASTEXITCODE
False
3
Packaged with "V3 Host (Windows) x64" :
PowerShell Code
Double-click the code block to select all.
PS C:\Test> .\TestExit.exe;$?;$LASTEXITCODE
True
Is there a way to let the Windows version return an exit code?

Comment on the result of the command line version for those who are interested in:
If only $script:ExitCode is defined this value is the return code of the package.
If also $global:ExitCode is defined the global value is the return code of the package.
If the value of $ExitCode isn't numeric (e.g. "y" or $null) then $? is True and $LASTEXITCODE is 0.
Numeric strings ($ExitCode = "123") will work like numeric values.

Martin