0
Powershellは、ExecutionPolicyエラーでERRORLEVEL変数を設定しません。
これで、スクリプトが失敗したことをバッチコードでどのように判断できますか?ExecutionPolicyエラー後にPowershellにERRORLEVEL変数を強制的に設定する方法
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
私が考えることができる唯一の方法は、try/catchを使用して広範なコマンドでスクリプト呼び出しをラップし、catchブロックでexit SomeNumを押します。 –
前のコメントと同じように、 'if($ some-var -eq 'true'){exit 0} else {exit 1};' – elzooilogico