为什么我需要 "Unblock-File" 即使执行策略是 RemoteSigned?

Why do I need "Unblock-File" even though execution policy is RemoteSigned?

我有一个调用 powershell 脚本的批处理文件 运行。

Powershell.exe -ExecutionPolicy RemoteSigned -File %1

%1 参数是 file_name.ps1

当我从我的本地驱动器 运行 它时,脚本 运行 没问题。

然而,我将脚本移动到共享驱动器上的 运行,当我尝试从那里 运行 连接它时,它在继续之前给出了这样的提示:

问题是 autosys 必须绕过这个提示,否则会报错。

但是为什么当我 运行 本地驱动器上的脚本没有提示时,这甚至是共享驱动器中的一个问题?我应该怎么做才能解决它?

我尝试在 powershell 中传递 Unblock-File -Path some_path 但它显然无法识别 cmdlet。

好的,所以在无法加载文件的区域标识之后,我尝试了 ByPass 策略,如下所示:

Powershell.exe -ExecutionPolicy ByPass -File %1

这让它起作用了....而不是 RemoteSigned/Unrestricted...

基于此处的 MSDN 文章:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-6

RemoteSigned: Scripts can run.

Requires a digital signature from a trusted publisher on scripts and configuration files that are downloaded from the Internet (including e-mail and instant messaging programs).

Does not require digital signatures on scripts that you have written on the local computer (not downloaded from the Internet).

Runs scripts that are downloaded from the Internet and not signed, if the scripts are unblocked, such as by using the Unblock-File cmdlet.

Unrestricted: Unsigned scripts can run. (This risks running malicious scripts.)

Warns the user before running scripts and configuration files that are downloaded from the Internet.

但是我的脚本是从一个驱动器本地复制到另一个驱动器的,它不是从互联网上下载的...并且在文件属性中,没有 "Unblock" 按钮,并且取消阻止 cmdlet 对我不起作用无论如何。

所以为了避免警告,唯一有效的方法是 ByPass

Bypass: Nothing is blocked and there are no warnings or prompts.