- Aug
- 2,134
- 92
Code:
c:\users\jlc\utils>ver
TCC 23.00.30 x64 Windows 7 [Version 6.1.7601]
Code:
@setlocal
@echo off
pshell /s "[ValidateRange(1,10)] [int]$x = 1"
echo ErrorLevel %_?
pshell /s "$x = 11"
echo ErrorLevel %_?
echo %@pshell[$x = 11]
echo ErrorLevel %_?
endlocal
Sample run of above...
Code:
c:\users\jlc\utils>ValidateRange.btm
ErrorLevel 0
PSHELL: System.Management.Automation.ValidationMetadataException : The variable cannot be validated because the value 11 is no
t a valid value for the x variable.
ErrorLevel 1510
PSHELL: System.Management.Automation.ValidationMetadataException : The variable cannot be validated because the value 11 is no
t a valid value for the x variable.
ErrorLevel 2
This code works as expected, that is, it returns an error because 11 is not in the range 1 to 10.
Therefore, why do PSHELL and @PSHELL return different errorlevels for the same error?
Joe