简体   繁体   English

Powershell脚本-禁止显示安全弹出窗口

[英]Powershell script - suppress security popup

I downloaded PS script from http://poshcode.org/2216 . 我从http://poshcode.org/2216下载了PS脚本。 Whenever I try to run this script, security popup appears: "Run only scripts that you trust. While Scripts from the internet can be usefull, 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. (...)". 每当我尝试运行此脚本时,都会弹出安全弹出窗口:“仅运行您信任的脚本。虽然来自Internet的脚本可能有用,但此脚本可能会损害您的计算机。如果您信任此脚本,请使用Unblock-File cmdlet来执行以下操作:允许脚本在没有此警告消息的情况下运行。(...)”。

So I executed Unblock-File .\\Send-File.ps1 but nothing changed. 所以我执行了Unblock-File .\\Send-File.ps1但是没有任何变化。 I also tried other variations like Get-Content .\\SendFile | Unblock-File 我还尝试了其他变体,例如Get-Content .\\SendFile | Unblock-File Get-Content .\\SendFile | Unblock-File . Get-Content .\\SendFile | Unblock-File Nothing seems to work. 似乎没有任何作用。

Does anyone know what is the proper way to unblock PowerShell script? 有谁知道解除阻止PowerShell脚本的正确方法是什么? Thanks in advance. 提前致谢。

您还可以从备用数据流中擦除ZoneId:

set-Content Send-File.ps1 -Stream zone.identifier -Value ''

To unblock a particular script file, Sam's answer will be ok. 要取消阻止特定脚本文件,Sam的答案是可以的。 You also can run a script without actually unblocking it by bypassing your PowerShell execution policy explicitly. 您还可以通过显式绕过PowerShell执行策略来运行脚本,而无需实际对其进行阻止。 To do that execute the following console command: 为此,请执行以下控制台命令:

powershell.exe -ExecutionPolicy Bypass .\\Send-File.ps1

... and the script will start ...并且脚本将开始

右键单击下载的脚本,选择属性并取消阻止。

By default the downloaded PS script will be treated as unsafe. 默认情况下,下载的PS脚本将被视为不安全。 You need to set Powershell's execution policy to bypass the security check for this particular file. 您需要设置Powershell的执行策略来绕过此特定文件的安全检查。

To do that, execute: 为此,执行:

Set-ExecutionPolicy Bypass -File (...)

(Note that it is possible to run the above command with no File specified, which globally sets the execution policy to bypass the security check; we do not recommend you do that!) (请注意,可以在不指定文件的情况下运行上述命令,这会全局设置执行策略以绕过安全检查;我们不建议您这样做!)

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

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