Pav*_*uva 394 powershell
当我尝试执行 PowerShell 脚本时,出现此错误:
无法加载文件 C:\Common\Scripts\hello.ps1,因为在此系统上禁用了脚本的执行。有关更多详细信息,请参阅“get-help about_signing”。
在 line:1 char:13
+ .\hello.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ fullyQualifiedErrorId : RuntimeException
Pav*_*uva 566
使用“以管理员身份运行”选项启动 Windows PowerShell。只有计算机上管理员组的成员才能更改执行策略。
通过输入启用运行未签名的脚本:
set-executionpolicy remotesigned
Run Code Online (Sandbox Code Playgroud)这将允许运行您在本地计算机上编写的未签名脚本和来自 Internet 的签名脚本。
另请参阅Microsoft TechNet 库中的运行脚本。
Wil*_*sum 120
默认执行策略设置为受限,您可以通过运行Get-ExecutionPolicy来查看它:
Get-ExecutionPolicy
Run Code Online (Sandbox Code Playgroud)
像这样运行Set-ExecutionPolicy以切换到无限制模式:
Set-ExecutionPolicy unrestricted
Run Code Online (Sandbox Code Playgroud)
MDM*_*313 75
在我用于开发脚本的机器上,我将使用 -unrestricted 如上所述。但是,在将我的脚本部署到最终用户计算机时,我将只使用 -executionpolicy 开关调用 powershell:
powershell.exe -noprofile -executionpolicy bypass -file .\script.ps1
Run Code Online (Sandbox Code Playgroud)
小智 29
我们可以通过以下命令获取当前 ExecutionPolicy 的状态:
Get-ExecutionPolicy;
Run Code Online (Sandbox Code Playgroud)
默认情况下它是Restricted。为了允许 PowerShell 脚本的执行,我们需要将此 ExecutionPolicy 设置为Bypass或Unrestricted。
我们可以为当前用户为策略Bypass
或Unrestricted
通过使用任何下面的PowerShell命令:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force;
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force;
Run Code Online (Sandbox Code Playgroud)
无限制策略加载所有配置文件并运行所有脚本。如果您运行从 Internet 下载的未签名脚本,则会在运行前提示您获得许可。
而在Bypass策略中,在脚本执行期间没有任何内容被阻止并且没有警告或提示。Bypass ExecutionPolicy 比 Unrestricted 更宽松。
根据 Windows 版本和配置,即使在Unrestricted
模式下,您也可能收到以下警告:
Run Code Online (Sandbox Code Playgroud)Security warning Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning message. Do you want to run? [D] Do not run [R] Run once [S] Suspend [?] Help (default is "D")
解决方案是使用“绕过”策略,通过以下命令启用:
Set-ExecutionPolicy Bypass
Run Code Online (Sandbox Code Playgroud)
从文档:
绕过:没有被阻止,也没有警告或提示。
这显然是不安全的,请理解所涉及的风险。
小智 5
一个 .reg 文件:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\PowerShell]
"EnableScripts"=dword:00000001 "ExecutionPolicy"="Bypass"
Run Code Online (Sandbox Code Playgroud)
和:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\PowerShell]
"EnableScripts"=dword:00000001 "ExecutionPolicy"="Unrestricted"
Run Code Online (Sandbox Code Playgroud)
确实也有效。
归档时间: |
|
查看次数: |
1683805 次 |
最近记录: |