Powershell return code and parameters - by Mathias MICHEL

Status : 

 


5
0
Sign in
to vote
ID 638771 Comments
Status Active Workarounds
Type Bug Repros 4
Opened 1/27/2011 6:20:48 AM
Access Restriction Public

Description

When a script contains a param() statement, with a parameter using the Parameter() statement, the return code of executing this script with powershell commandlien, exit code is always zero, whatever the Parameter statement contains.

check_ko.ps1:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
param( [Parameter()] [string] $DATE )
$_CODE = 10
@"
Return Code: $_CODE
"@
exit $_CODE @"
Return Code: $_CODE
"@

exit $_CODE 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

check_ok.ps1:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
param( [string] $DATE )
$_CODE = 10
@"
Return Code: $_CODE
"@
exit $_CODE @"
Return Code: $_CODE
"@

exit $_CODE 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


Check the reproduction steps in the details.
Sign in to post a comment.