网络驱动器上的 Powershell 脚本即使在运行 Unblock-File 后仍然给出安全提示

问题描述 投票:0回答:2

我正在尝试运行我编写的 Powershell Cmdlet。

它存储在映射到

Z:\...
的网络驱动器上。

我已在管理员模式下启动Powershell并将执行策略设置为

Unrestricted

我已在我的 Cmdlet 及其调用的每个脚本上运行

Unblock-File

我使用其绝对路径或以

.\
开头的相对路径来调用我的 Cmdlet。

但是,制表符完成功能仍然不适用于我的 Cmdlet 参数,并且我仍然收到此安全警告:

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 <file-name>?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is “D”):

我做错了什么?

powershell window
2个回答
2
投票

就我而言,答案是 Windows 配置为将网络驱动器视为公共互联网上的位置。

解决方案是启动 Internet Options 控制面板,导航到 Security 选项卡,然后将我的脚本所在的网络共享(例如

\\networkshare
)添加到 Local Intranet 安全区域。

之后,制表符补全功能可以与我的 Cmdlet 参数一起正常工作,并且脚本可以在没有任何安全警告的情况下执行。


0
投票

谢谢你,我也遇到了同样的问题。这解决了它。

© www.soinside.com 2019 - 2024. All rights reserved.