PowerShell 的 .ps1 如何執行
PowerShell 有4種執行原則:
- Restricted:所有PowerShell Script(.ps1) 皆無法執行。(Windows系統預設)。
- AllSigned:所有PowerShell Script都要經過受信任的發行者簽屬過後才可執行。
- RemoteSigned:針對從異地下載下來的PowerShell Script需要經過受信任的發行者簽屬過後才可執行,本機的PowerShell Script可直接執行。
- Unrestricted:無限制,所有PowerShell Script皆可執行。
在 PowerShell 執行下面指令即可
$ Set-ExecutionPolicy RemoteSigned
要以系統管理員的身份執行, 才不會出錯
參考指令
- To get all of the execution policies that affect the current session and display them in precedence order:
Get-ExecutionPolicy -List
- 本機的PowerShell Script可直接執行
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
- 目前的使用者可以執行
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
- 移除執行原則 Remove Your Execution Policy
# 移除本機可執行的原則 Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope LocalMachine # 移除現行使用者可執行的原則 Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser
你必須 登入 才能發表評論。