PowerShell 默認(rèn)不允許執(zhí)行*.ps1腳本文件。運(yùn)行ps1文件會(huì)得到下面的錯(cuò)誤:
File C:\Temp\Test.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get- help about_signing" for more details.
At line:1 char:19
+ c:\Temp\Test.ps1 <<<<
可以通過(guò)Get-ExecutionPolicy,來(lái)取得當(dāng)前策略。
用Set-ExecutionPolicy設(shè)置當(dāng)前策略。
下面的命令可以解決上面的錯(cuò)誤
PS C:\Windows\system32> Set-ExecutionPolicy RemoteSigned <按回車>
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic. Do you want to change the execution
policy?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):<按Y>
在PowerShell中的執(zhí)行
Policy的有效參數(shù):
-- Restricted: 不載入任何配置文件,不運(yùn)行任何腳本。 "Restricted" 是默認(rèn)的。
-- AllSigned: 只有被Trusted publisher簽名的腳本或者配置文件才能使用,包括你自己再本地寫(xiě)的腳本
-- RemoteSigned: 對(duì)于從Internet上下載的腳本或者配置文件,只有被Trusted publisher簽名的才能使用。
-- Unrestricted: 可以載入所有配置文件,可以運(yùn)行所有腳本文件. 如果你運(yùn)行一個(gè)從internet下載并且沒(méi)有簽名的腳本,在運(yùn)行之前,你會(huì)被提示需要一定的權(quán)限。
-- Bypass: 所有東西都可以使用,并且沒(méi)有提示和警告.
-- Undefined: 刪除當(dāng)前scope被賦予的Execution Policy. 但是Group Policy scope的Execution Policy不會(huì)被刪除.
聯(lián)系客服