即使运行 Unblock-File 后,网络驱动器上的 Powershell 脚本仍会给出安全提示
我正在尝试运行我编写的 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”):
我做错了什么?
I am trying to run a Powershell Cmdlet that I wrote.
It is stored on a network drive mapped to Z:\...
.
I have launched Powershell in administrator mode and set the execution policy to Unrestricted
.
I have run Unblock-File
on my Cmdlet, and every script that it calls.
I am calling my Cmdlet either with its absolute path, or with a relative path beginning with .\
.
But still, tab completion is not working for my Cmdlet's parameters, and I still get this security warning:
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”):
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我而言,答案是 Windows 配置为将网络驱动器视为公共互联网上的位置。
解决方案是启动 Internet 选项 控制面板,导航到安全 选项卡,然后添加我的脚本所在的网络共享(例如,
\\networkshare
)到本地 Intranet 安全区域。之后,制表符补全可以与我的 Cmdlet 参数一起正常工作,并且脚本可以在没有任何安全警告的情况下执行。
The answer, in my case, is that Windows was configured to regard the network drive as a location on the public internet.
The solution was to launch the Internet Options control panel, navigate to the Security tab, and add the network share where my scripts were located (eg,
\\networkshare
) to the Local intranet security zone.Afterwards, the tab completion worked correctly with my Cmdlet's parameters, and the script could execute without any security warning.
设置 Intranet 站点:包括在 GPO 中启用的所有网络路径 (UNC)。计算机配置>管理模板> Windows 组件 >互联网浏览器>安全页面
Set the Intranet Sites: Include all network paths (UNCs) to Enabled in a GPO. Computer Config > Admin Templates > Windows Components > Internet Explorer > Security Page