从命令行忽略“安全警告"运行脚本 [英] Ignore 'Security Warning' running script from command line

查看:68
本文介绍了从命令行忽略“安全警告"运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我信任的共享文件夹中执行脚本:

I am trying to execute a script from shared folder that I trust:

PowerShell -file "\\server\scripts\my.ps1"

但我收到安全警告,必须按R"才能继续

But I get a security warning, and have to press 'R' to continue

安全警告只运行脚本你信任.虽然脚本来自互联网很有用,这个脚本可能会损害您的计算机.做你想跑\server\scripts\my.ps1?[D] 不要运行 [R] 运行一次 [S] 暂停 [?]帮助(默认为D"):d

Security Warning Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your computer. Do you want to run \server\scripts\my.ps1? [D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"): d

我可以忽略这个警告吗?我想要的伪代码是:

Can I ignore this warning? The desired pseudo code I want is:

PowerShell -IGNORE_SECURITY_WARNING -file "\\server\scripts\my.ps1"

推荐答案

这在 Lee Holmes 博客上的标准图像中的 PowerShell 执行策略"Windows Power Shell 博客上的PowerShell 的安全指导原则".

This is touched in "PowerShell Execution Policies in Standard Images" on Lee Holmes' Blog and "PowerShell’s Security Guiding Principles" on the Windows Power Shell Blog .

总结有些机器将 UNC 路径视为大坏互联网,因此 PowerShell 将它们视为远程文件.您可以在这些服务器上禁用此功能 (UncAsIntranet = 0,) 或将远程计算机添加到您的受信任主机.

Summary Some machines treat UNC paths as the big bad internet, so PowerShell treats them as remote files. You can either disable this feature on those servers (UncAsIntranet = 0,) or add the remote machines to your trusted hosts.

如果您不想做任何事情,PowerShell v2 支持一个 -ExecutionPolicy 参数,它完全符合您的伪代码的要求.PowerShell -ExecutionPolicy Bypass -File (...).

If you want to do neither, PowerShell v2 supports an -ExecutionPolicy parameter that does exactly what your pseudocode wants. PowerShell -ExecutionPolicy Bypass -File (...).

这篇关于从命令行忽略“安全警告"运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆