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

标签 powershell batch-file autosys

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

Powershell.exe -ExecutionPolicy RemoteSigned -File %1

%1 参数是 file_name.ps1

当我从本地驱动器运行它时,脚本运行良好。

但是,我将脚本移动到共享驱动器上运行,当我尝试从那里运行它时,它会在继续之前给出这种提示:

Unblock_file prompt

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

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

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

最佳答案

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

Powershell.exe -ExecutionPolicy ByPass -File %1

使它工作....而不是 RemoteSigned/Unrestricted...

基于此处的 MSDN 文章:https://learn.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.

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

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

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

关于powershell - 为什么我需要 "Unblock-File",即使执行策略是 RemoteSigned?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52521915/

相关文章:

PowerShell 代码格式

PowerShell:获取 'tmp' 环境变量原始值

job-scheduling - autosys中待处理机器的含义

ksh - 将 jil 错误输出重定向到日志文件

perl - 在程序中使用 __DATA__

string - 将 Unicode 字符串转换为 ASCII

powershell - 使用 Powershell Limit-Eventlog 设置 Windows 日志最大大小

c# - Globalprotect VPN 批处理文件或 C# 代码

c++ - 从程序执行批处理文件

java - 以管理员身份执行Java程序