![](/img/trans.png)
[英]Revert Back PowerShell after “Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force”
[英]How to force Powershell set ERRORLEVEL variable after ExecutionPolicy error
Powershell不會在ExecutionPolicy錯誤上設置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
set NLS_LANG=American_America.AL32UTF8
REM your code
echo %ERRORLEVEL%
這是一個簡單的批處理文件。 %ERRORLEVEL%將在提示中顯示錯誤
在底部,您可以輸入:
if (-not $?) { exit 1 }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.