简体   繁体   中英

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

I have a batch file that calls powershell script and runs it.

Powershell.exe -ExecutionPolicy RemoteSigned -File %1

%1 argument is the file_name.ps1

When i run it from my local drive, the script runs fine.

however, I moved the scripts to run on a shared drive, and when i try running it from there, it gives this kind of prompt before proceeding:

Unblock_file提示

The problem with this is autosys has to bypass this prompt, otherwise its giving error.

But why is this even an issue in the shared drive when if i run the script on local drive it doesn't prompt this? and what should i do to resolve it?

I tried passing in the Unblock-File -Path some_path in powershell but its apparently not recognized cmdlet.

Ok, so after being unable to load the zone identification for the file, I tried ByPass policy instead as follows:

Powershell.exe -ExecutionPolicy ByPass -File %1

THAT made it work....instead of RemoteSigned/Unrestricted...

Based on MSDN article here: 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.

but my script was copied locally there from one drive to another, its not downloaded from the internet...and in the file properties, there was no "Unblock" button, and Unblock cmdlet wouldnt work for me anyways.

So to avoid the warning, the only thing that worked is ByPass

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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