對這文章發表回應
發表限制: 非會員 可以發表
發表者: 冷日 發表時間: 2015/12/18 3:22:56
Powershell 檔案無法載入,因為這個系統上已停用指令碼執行。
Posted on 2012年七月25日 by taien
Powershell 執行 ps1 檔時出現: 檔案無法載入,因為這個系統上已停用指令碼執行。如需詳細資訊,請參閱 “get-help about_signing"。
原因是第一次在電腦上啟動 Windows PowerShell 時,可能會實行 Restricted 執行原則 (預設值)。Restricted 原則不會允許任何指令碼執行。
若要允許執行已簽署的指令碼
在PowerShell console下執行 Set-ExecutionPolicy RemoteSigned
PS C:\> Set-ExecutionPolicy RemoteSigned
Set-ExecutionPolicy 設定詳細參考
Restricted | This is the default execution policy upon installation. When this policy is in effect, script execution is disabled. This includes script modules, profile files and types, and format files. PowerShell itself isn’t disabled and may still be used as an interactive command interpreter. Although this is the most secure policy, it severely impacts your ability to use PowerShell for automation. |
AllSigned | When the execution policy is AllSigned, scripts can be executed but they must be Authenticode-signed before they’ll run. When running a signed script, you’ll be asked if you want to trust the signer of the script. Section 21.4 covers the details of script signing. AllSigned is still a secure policy setting, but it makes script development difficult. In an environment where scripts will be deployed rather than created, this is the best policy. |
RemoteSigned | RemoteSigned requires that all scripts that are downloaded from a remote location be Authenticode-signed before they can be executed. Note that this depends on whether the application doing the download marks the script as coming from a remote location. Not all applications do this. Anything downloaded by Internet Explorer 6.0 or above, Outlook, or Outlook Express will be properly marked. RemoteSigned is the minimum recommended execution policy setting. It’s the best policy setting for script development. |
Unrestricted | When the execution policy is Unrestricted, PowerShell will run any script. It will still prompt the user when it encounters a script that has been downloaded. Unrestricted is the least secure setting. We don’t recommend that you use this setting, but it may be necessary in some developer scenarios where RemoteSigned is still too restrictive. |
Bypass (v2 only) | Nothing is blocked and there are no warnings or prompts. This execution policy is designed for configurations in which PowerShell scripts are part of a larger application that has its own security model. The Windows Diagnostics feature in Windows 7 is a good example of this type of application. |
Undefined (v2 only) | Removes the currently assigned execution policy from the current scope. This parameter won’t remove an execution policy that’s set in a Group Policy scope (User scope or Machine scope). |
節錄至:chapter 21, Security, security, security, Windows PowerShell in Action, Second Edition
參考:
原文出處: Powershell 檔案無法載入,因為這個系統上已停用指令碼執行。 | Taien's blog