默認狀況下Windows server 2008R2的腳本執行權限是RemoteSigned,本地建立的腳本都是能夠運行的,從網絡下載的必需要有數字簽名纔可以執行。實際使用過程當中,用戶可能會遇到腳本執行不了的現象。這裏對腳本的執行權限稍做探討,你們能夠測試一下,歡迎留言討論。shell
獲取當前會話的腳本執行權限策略:網絡
PS D:\powershell_study> Get-ExecutionPolicy RemoteSigned
powershell有四種腳本運行權限策略,能夠經過命令man Set-ExecutionPolicy來查看。
ide
PS D:\powershell_study> man Set-ExecutionPolicy NAME Set-ExecutionPolicy SYNOPSIS Changes the user preference for the Windows PowerShell execution policy. SYNTAX Set-ExecutionPolicy [-ExecutionPolicy] {Unrestricted | RemoteSigned | AllSigned | Restricted | Default | Bypass | Undefined} [[-Scope] {Process | CurrentUser | LocalMachine | UserPolicy | MachinePolicy}] [-Confirm] [-Force] [-WhatIf] [<CommonParameters>] ..................
Unrestricated是不受限制的意思,AllSigned是全部的腳本都須要數字簽名驗證,Restricted是不讓任何腳本執行的意思。測試
設置腳本運行權限的方式:
spa
PS C:\>Set-ExecutionPolicy -ExecutionPolicy RemoteSignedrest