默认状况下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