Powershell 脚本 - 抑制安全弹出窗口

Powershell script - suppress security popup

我从 http://poshcode.org/2216 下载了 PS 脚本。每当我尝试 运行 此脚本时,都会出现安全弹出窗口:"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. (...)".

所以我执行了 Unblock-File .\Send-File.ps1 但没有任何改变。我还尝试了其他变体,例如 Get-Content .\SendFile | Unblock-File。似乎没有任何效果。

有谁知道解锁 PowerShell 脚本的正确方法是什么?提前致谢。

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

默认情况下,下载的 PS 脚本将被视为不安全的。您需要设置 Powershell 的执行策略以绕过针对此特定文件的安全检查。

为此,执行:

Set-ExecutionPolicy Bypass -File (...)

(请注意,可以运行上述命令不指定文件,全局设置执行策略绕过安全检查;我们不建议您这样做!)

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

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

要取消阻止特定的脚本文件,Sam 的回答是可以的。 您还可以 运行 一个脚本,而无需通过显式绕过您的 PowerShell 执行策略来实际解锁它。 为此,请执行以下控制台命令:

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

...脚本将开始