简体   繁体   English

从 Powershell ISE 运行脚本时如何绕过执行策略

[英]How can I bypass execution policy when running scripts from Powershell ISE

So I can write a script in Powershell ISE, not save it, and it will run (F5/green arrow on the ISE).所以我可以在 Powershell ISE 中编写一个脚本,而不是保存它,它会运行(ISE 上的 F5/绿色箭头)。 Once I save it, I get the error saying I can't run saved scripts.保存后,我收到错误消息,提示我无法运行保存的脚本。 If I open a Powershell window in the directory the saved script exists, I can run it with如果我在保存的脚本存在的目录中打开一个 Powershell 窗口,我可以运行它

powershell -ExecutionPolicy ByPass -File script.ps1

But is there a way I can get this to work when running it via the ISE's green arrow/F5?但是,当我通过 ISE 的绿色箭头/F5 运行它时,有没有办法让它工作? I don't have admin access to this PC我没有这台电脑的管理员权限

Edit: Windows 10编辑:Windows 10

Ok so I just found out you can set Execution Policy for yourself (current user) without having admin rights.好的,我刚刚发现您可以为自己(当前用户)设置执行策略而无需管理员权限。 So if you're coming here from google do this:所以如果你从谷歌来到这里,请执行以下操作:

Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "RemoteSigned"

Also you can run individual script without setting Execution Policy for current user, by passing Execution Policy only for file script.您还可以通过仅传递文件脚本的执行策略来运行单个脚本,而无需为当前用户设置执行策略。

For example:例如:

Powershell -executionpolicy RemoteSigned -File "C:\\scripts\\script.ps1"

Very convenient for scheduled tasks in the Windows Task Scheduler to run PowerShell commands (scripts).非常方便在 Windows Task Scheduler 中的计划任务运行 PowerShell 命令(脚本)。

That's my addition for google users这是我对谷歌用户的补充

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM