Powershell does not set ERRORLEVEL variable on an ExecutionPolicy error.
So how can one determine in batch code that the script has failed?
C:\Windows\system32>powershell -File myScript.ps1
Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed.
File myScript.ps1 cannot be loaded. The file myScript.ps1 is not digitally signed. You cannot run this script on the current system.
For more information about running scripts and setting execution policy, see about_Execution_Policies at
http://go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess
C:\Windows\system32>echo %ERRORLEVEL%
0
exit SomeNumin the catch block.if ($some-var -eq 'true') {exit 0} else {exit 1};