当您从Internet下载图像、文档等文件时,它们会被视为不受信任的文件(untrusted files)。因此,如果恶意软件以JPEG 格式(JPEG)下载,它将能够在计算机上执行任何操作。我相信您已经看到了无法重命名文件的错误,或者如果它是一个文档,它仍然处于只读模式,等等。但是,如果您要下载大量文件,并且所有文件都应该被解锁,这可能会很烦人。我们已经了解了如何取消阻止文件以及如何使用 PowerShell或注册表将(Registry)取消阻止(Unblock)文件项添加到上下文菜单中。在这篇文章中,我们将分享如何批量解锁文件(bulk unblock files)从网上下载。
如何查找文件是否被阻止?
右键单击(Right-click)任何文件,然后从上下文菜单中选择属性。如果文件被阻止,则在“常规(General)”选项卡下,您将收到安全警告。应该说
The file came from another computer and might be blocked to help protect this computer and might be blocked to help protect this computer.
您可以选中Unblock(Unblock)旁边的框,然后保存更改以取消阻止文件。当您选择多个文件时,此选项不可用,请转到属性。
Unblock-File 命令如何工作?
PowerShell提供了一个内置命令Unblock-File来更改从Internet下载的(Internet)PowerShell脚本文件的解除阻止状态,但它适用于所有类型的文件。在内部, Unblock-File cmdlet 删除了“ Zone.Identifier 备用数据流(Zone.Identifier alternate data stream)”。它的值为“3”,表示它是从Internet下载的。
如果您在PowerShell脚本上应用此功能,它可以取消阻止从Internet下载的(Internet)PowerShell脚本文件,以便您可以运行它们,即使PowerShell执行策略是 RemoteSigned 也是如此。该命令的语法如下:
Unblock-File
[-Path]/-LiteralPath <String[]>
[-WhatIf]
[-Confirm]
[<CommonParameters>]
批量取消阻止从(Bulk Unblock)Internet下载的多个文件
该命令需要单个或多个文件。 任何(Any)可以将文件列表传递给它的输出都可以工作。这是一个例子:
dir <path> | Unblock-File
- 上面的命令使用DIR命令生成文件列表,然后将其发送到 Unblock-File 命令行开关。
- 您不会收到任何形式的确认,但所有文件都将被解锁。
如果您只想取消阻止包含例如TWC的文件名,则命令将如下所示:
dir <path>\*TWC* | Unblock-File
需要逐一确认文件解除阻塞的可以在命令的同时加上-Confirm选项。然后它将提示您输入每个文件。如果您选择是,那么它将解锁文件,否则将移动到下一个。
当您从Internet(Internet)下载文件,然后与其他人共享时,它会派上用场。数据保持锁定状态,除非文件未解锁,否则他们将能够重命名文件。您可以使用此命令解锁所有文件,然后发送。
我希望这篇文章很容易理解,并且您能够解除对从Internet下载的多个文件或批量文件的阻止。
How to bulk Unblock multiple files downloaded from the Internet
When you dоwnloаd a filе from the Internet like images, documents, etc., they are treated as untrusted files. So if malware is downloaded in the form of JPEG, it will be able to execute anything on the computer. I am sure you have seen errors where you cannot rename the files or if it’s a document, it remains in read-only mode, and so on. However, it can be annoying if you are downloading a lot of files, and all of them should be unlocked. We have seen how to Unblock a file and how to add Unblock file item to the context menu using PowerShell or Registry. In this post, we will share how you can bulk unblock files downloaded from the Internet.
How to find if the file is blocked?
Right-click on any of the files, and select Properties from the context menu. If the file is blocked, then under the General tab, you will have a security warning. It should say
The file came from another computer and might be blocked to help protect this computer and might be blocked to help protect this computer.
You can check the box next to Unblock, and then save the changes to unblock the file. This option is not available when you select multiple files, go to properties.
How does the Unblock-File command work?
PowerShell offers a built-in command — Unblock-File — to change the unblock status of PowerShell script files that were downloaded from the Internet, but it works on all kinds of files. Internally, the Unblock-File cmdlet removes the “Zone.Identifier alternate data stream“. It has a value of “3” to indicate that it was downloaded from the Internet.
If you apply this on PowerShell scripts, it can unblock PowerShell script files that were downloaded from the Internet so you can run them, even when the PowerShell execution policy is RemoteSigned. The syntax for the command is as follows:
Unblock-File
[-Path]/-LiteralPath <String[]>
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Bulk Unblock multiple files downloaded from the Internet
The command needs single or multiple files. Any output which can pass a list of files to it will work. Here is an example:
- Copy the path where the blocked files are available
- Open PowerShell with admin privileges.
- Type the following and execute
dir <path> | Unblock-File
- The command above uses the DIR command to generate a list of files, and then it is sent to the Unblock-File commandlet.
- You will not receive any kind of confirmation, but all the files will be unblocked.
If you want only to unblock files names of which include e.g., TWC, then the command will be like:
dir <path>\*TWC* | Unblock-File
Those who need to confirm unblocking for files one by one can add -Confirm option along with the command. It will then prompt you for each file. If you choose yes, then it will unblock the file, else will move to the next.
It comes in very handy when you download a file from the Internet, and then share it with somebody else. The data remain locked, and they will be able to rename the file unless it is unlocked. You can use this command to unlock all the files, and then send it.
I hope the post was easy to follow, and you were able to unblock multiple files or bulk files downloaded from the Internet.