Unblock Files Using PowerShell

Unblock Files Using PowerShell

If we are using a Windows-based operating system, you may have encountered the message:

This file came from another computer and might be blocked to help protect this computer.

For example, a warning might pop up when you try to open a file that you downloaded from the internet. This article will discuss how to unblock and allow files downloaded from the internet using PowerShell.

Unblock Files Using PowerShell

For this article, we will use the PowerShell native cmdlet, Unblock-File, introduced in PowerShell 3.0.

The Unblock-File cmdlet lets us open files we downloaded from the internet. In addition, it unblocks Windows PowerShell script files we downloaded from the internet so we can run them, even when the Windows PowerShell execution policy is set to RemoteSigned.

These files are default blocked to protect the computer from untrusted files.

Basic Syntax:

Unblock-File [-Path*] <String[]> [-Confirm] [-WhatIf] [<CommonParameters>]

Internally, the Unblock-File cmdlet removes the Zone.Identifier alternate data stream, which has a value of 3 to indicate that we downloaded it from the internet. For more information about Windows PowerShell execution policies, see about_Execution_Policies.


Here are some of the parameters that we can use with the Unblock-File cmdlet:

  • -Confirm: This parameter prompts you for confirmation before running the cmdlet.

  • -LiteralPath: Specifies the files to unblock. Unlike Path, the value of the LiteralPath parameter is used as it is typed; no characters are interpreted as wildcards.

    If the path includes escaping characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret characters as escape sequences.

  • -Path: Specifies the files to unblock. Wildcard characters are supported.

  • -WhatIf: This shows what would happen if the cmdlet runs. The cmdlet is not run.


We can use the Unblock-File cmdlet by specifying the file path of the blocked file:

Unblock-File -Path C:\Downloads\SampleFile.exe

Primarily, we are using PowerShell because we either need to automate processes or process things in bulk. Since we can use the Unblock-File command in a pipeline, we can use the said command after querying for all contents in a folder.

Once queried, we will process all files in the Unblock-File command.

dir -Path "C:\Downloads" -Recurse | Unblock-File

In addition, the Unblock-File cmdlet works only in file system drives. The Unblock-File cmdlet performs the same operation as the Unblock button on the Properties dialog box in File Explorer.

Therefore, if you use the Unblock-File cmdlet on a not blocked file, the command does not affect the unblocked file, and the cmdlet does not generate errors.

Marion Paul Kenneth Mendoza avatar Marion Paul Kenneth Mendoza avatar

Marion specializes in anything Microsoft-related and always tries to work and apply code in an IT infrastructure.


Related Article - PowerShell File