2016-08-18 3 views
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 
+0

私が考えることができる唯一の方法は、try/catchを使用して広範なコマンドでスクリプト呼び出しをラップし、catchブロックでexit SomeNumを押します。 –

+0

前のコメントと同じように、 'if($ some-var -eq 'true'){exit 0} else {exit 1};' – elzooilogico

答えて

0
set NLS_LANG=American_America.AL32UTF8 

REM your code 

echo %ERRORLEVEL% 

これは、単純なバッチファイルです。 %ERRORLEVEL%はプロンプトにエラーを表示します

関連する問題