PowerShell ExecutionPolicy更改绕过 [英] PowerShell ExecutionPolicy Change Bypass
问题描述
我创建了一个powershell脚本并将其安排为每月运行,但是当我尝试手动运行脚本时,它总是提示Policy Change:
I created a powershell script and schedule it to run every month, but when I try to run script manually it's always prompt Policy Change:
当我按Enter大约1小时后,它仍然出现提示
我已经将ExecutionPolicy设置为Unrestricted,但是我听说Unrestricted仍然有来自未解析脚本的提示,我该如何绕过提示
I already set ExecutionPolicy to Unrestricted but I heard Unrestricted still have prompt from untrsuted script, how can I bypass the prompt
还是可以通过批处理文件运行.ps1并绕过执行策略?
or there is anyway to run .ps1 through batch file and bypass the executionpolicy ?
谢谢
推荐答案
只有三种方法可以做到这一点:
Only Three ways to do this:
- 在所选计算机上手动进行操作.
- 使用组策略在所有计算机或选定的计算机上启用它
- 使用.bat文件从中执行脚本.
选项1:
Set-ExecutionPolicy $POLICY -Force
Restricted
-无法运行任何脚本. Windows PowerShell只能在交互模式下使用.
Restricted
- No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned
-仅可运行由受信任的发布者签名的脚本.
AllSigned
- Only scripts signed by a trusted publisher can be run.
RemoteSigned
-下载的脚本必须先由受信任的发布者签名,然后才能运行.
RemoteSigned
- Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted
-无限制;所有Windows PowerShell脚本都可以运行.
Unrestricted
- No restrictions; all Windows PowerShell scripts can be run.
选项2:
- 在计算机配置"下导航到策略" \管理模板" \"Windows组件" \"Windows PowerShell".您应该看到一个名为打开脚本执行"的设置
- 双击设置.您将要启用它,然后从下拉菜单中选择一个选项.
- 选择您选择的政策. AllSigned,RemoteSigned和不受限制
- GPO是安全的,但它也可以很快变得不安全.在将新的GPO投入生产之前,请确保对其进行了测试.
选项3:
在.bat文件中运行跟踪
Run the folling inside a .bat file
powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -file "name_of_script.ps1"
希望这可以帮助您找到所需的答案.
Hope this helps you find the answer you are looking for.
这篇关于PowerShell ExecutionPolicy更改绕过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!