如下说明是翻译
: help Set-ExecutionPolicy
产生的帮助信息
.
译者
: Edengundam(
马涛
)
Set-ExecutionPolicy
大纲
修改
PowerShell
中执行策略的用户首选项
(
preference
)
.
语法
Set-ExecutionPolicy [-executionPolicy] {<Unrestricted> | <RemoteSigned> | <AllSigned> | <Restricted> | <Default>} [-whatIf] [-confirm] [<CommonParameters>]
详细描述
Set-ExecutionPolicy
修改
PowerShell
中执行策略的用户首选项
(
preference
)
.
执行策略是
Windows PowerShell
安全策略中的一部分
.
它将决定你是否可以载入配置文件
(
包括你的
Windows PowerShell profile
文件
)
和运行脚本
,
它将会在运行前确定哪些文件必须具有数字签名
(
digitally signed
)
.
参数
-executionPolicy <ExecutionPolicy>
为指定一个新的执行策略
.
参数名称
("-Name")
可以省略
.
合法取值如下
:
·
Restricted:
不载入配置文件
,
不执行脚本
. "Restricted"
是默认值
.
·
AllSigned:
所有的配置文件和脚本必须通过信任的出版商签名
(
trusted publisher
)
,
这里所指的脚本页包括你在本地计算机上创建的脚本
.
·
RemoteSigned:
所有从互联网上下载的脚本必须通过信任的出版商签名
(
trusted publisher
)
.
·
Unrestricted:
载入所有的配置文件和脚本
.
如果你运行了一个从互联网上下载且没有数字签名的脚本
,
在执行前你都会被提示是否执行
.
如下列出此参数接受的参数
:
·
Unrestricted
·
RemoteSigned
·
AllSigned
·
Restricted
·
Default
强制参数
?
|
true
|
参数位置
?
|
1
|
默认值
|
N/A
|
允许从管道绑定输入
?
|
true (
根据值
)
|
允许通配符扩展
?
|
false
|
-whatIf
描述执行此命令将会发生的现象
,
不会真正执行此命令
.
强制参数
?
|
false
|
参数位置
?
|
named
|
默认值
|
|
允许从管道绑定输入
?
|
false
|
允许通配符扩展
?
|
false
|
-confirm
执行命令前提示你进行确认
.
强制参数
?
|
false
|
参数位置
?
|
named
|
默认值
|
|
允许从管道绑定输入
?
|
false
|
允许通配符扩展
?
|
false
|
<
公共参数
>
此命令支持公共参数
: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable.
更多信息
,
输入
, "get-help about_commonparameters".
输入类型
注意
更多信息
,
输入
"Get-Help Set-ExecutionPolicy -detailed".
需要技术信息
,
输入
"Get-Help Set-ExecutionPolicy -full".
当你使用
Set-ExecutionPolicy
时
,
新用户的首选项将会写人注册表中
,
所以不会被更改
.
然而
,
如果计算机或用户的组策略
"Turn on Script Execution"
被开启
,
用户首选项将会写入注册表
,
此时并不会生效
, Windows PowerShell
将会显示信息解释此冲突
.
即使用户首选项比组策略更加严格
,
你也不能使用
Set-ExecutionPolicy
覆盖组策略设置
.
需要更多关于
Windows PowerShell
执行策略信息
(
也包括组策略
)
,
输入
"Get-Help About_Signing".
如果需要为该命令提供多个参数
,
请使用逗号进行分隔
.
例如
, "<parameter-name> <value1>, <value2>".
例
1
C:/PS>set-executionpolicy remotesigned
此命令将用户首选项的执行策略修改为
RemoteSigned.
例
2
C:/PS>Set-ExecutionPolicy Restricted
此命令试图设置
shell
执行策略为
"Restricted"
.
设置
"Restricted"
被写入注册表中
,
由于此设置与组策略设置冲突
,
因此没有生效
,
虽然这里的设置比组策略设置更加严格
.
Set-ExecutionPolicy : Windows PowerShell updated your local preference successfully, but the setting is overridden by the group policy applied to your system. Due to the override, your shell will retain its current effective execution policy of "AllSigned". Contact your group policy administrator for more information.
At line:1 char:20
+ set-executionpolicy <<<< restricted
相关链接
Get-ExecutionPolicy
Set-AuthenticodeSignature
Get-AuthenticodeSignature
about_signing