由于执行权限导致PowerShell Script无法启动
日期: 2010-02-22 类别: PowerShell 查看评论运行PowerShell脚本提示错误:
File C:\Users\xxx\Desktop\p.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:8
+ .\p.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
查了下原因,原来是PowerShell默认的执行权限的问题。在PowerShell中有4中执行权限:
- Restricted——默认的设置, 不允许任何script运行
- AllSigned——只能运行经过数字证书签名的script
- RemoteSigned——运行本地的script不需要数字签名,但是运行从网络上下载的script就必须要有数字签名
- Unrestricted——允许所有的script运行
可以使用Get-ExecutionPolicy来获取当前的权限,使用Set-ExecutionPolicy来更改执行权限
Stat.