gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 05:14:23 32 4
gpt4 key购买 nike

我有一个调用 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com