[ACCEPTED]-Unblock a file with PowerShell?-powershell-2.0

Accepted answer
Score: 50

If you are using PowerShell v3, you can 21 use the Unblock-File cmdlet.

The "blocking" part 20 is simply an alternate data stream of the 19 file, named "Zone.Identifier". You 18 can display it in CMD by using input redirection 17 (no other way to get to a stream in CMD, though):

H:\Downloads> more < test.exe:Zone.Identifier

You 16 can find them using dir /r on Windows Vista and 15 later:

2009-10-24  12:18        54.538.056 test.exe
                                 24 test.exe:Zone.Identifier:$DATA

Also in CMD you can easily get rid 14 of that by overwriting it (using output 13 redirection, this time):


which isn't quite the 12 same as removing the ADS completely, but 11 works in that Explorer doesn't complain 10 anymore.

There doesn't seem to be native 9 support for handling ADS from within PowerShell 8 (as mentioned on The PowerShell Guy's blog 7 here. That article also has some information 6 how to get that functionality in PowerShell). You 5 could, however, simply call cmd:

cmd /c "echo.>test.exe:Zone.Identifier"

That works 4 from PowerShell as well.

Another option would 3 be Mark Russinovich's streams utility which allows 2 you to inspect a file's ADS and also to 1 delete them. So

streams -d myDownloadedFile.exe

does work as well.

Score: 9

The PoshCode module includes Set-DownloadFlag 6 and Remove-DownloadFlag functions which 5 work as advertised. :) I've just pulled 4 that piece out into it's own script contribution 3 http://poshcode.org/1430 ... it will work on PowerShell 1 too, if 2 you use the New-Type function in place of 1 Add-Type ( http://poshcode.org/720 )

Score: 5

Oneliner to remove zone informarion(inspired 5 by accepted answer) for all children (with 4 correct quoting).

get-childitem -rec | % { cmd /c "echo.>""$($_.FullName)"":Zone.Identifier" }

Not strictly answer to 3 the question, just want to make sure when 2 I next come up with this problem there is 1 solution already :).

PS. Works in PS 2.0

Score: 4

new to posting in forums like this and this 4 might be an old topic but here is what you 3 are looking for.

get-item -Path "path to file(s)" -Stream "Zone.Identifier" -ErrorAction "SilentlyContinue"

This should list out files 2 that are blocked only.

Unblock-File -Path "Path to blocked file(s)"

This will unblock 1 them.

Score: 2

To unblock a folder and it's subfolder recursive 2 (>= PowerShell v3) you can use the Get-ChildItem (gci) command:

Get-ChildItem "C:\Temp\" -recurse | Unblock-File

where 1 C:\Temp is the starting folder.

Score: 1

Remove the alternate file stream using Streams.exe see 1 this post: http://www.paraesthesia.com/archive/2010/05/19/unblocking-multiple-files-at-once.aspx

Score: 1

I wrote a little function that uses the 14 Win32 API to delete the Zone.Identifier NTFS alternate 13 data stream which is what Windows uses to 12 determine whether a file is to be blocked.

.NET 11 doesn't have access to alternate data streams 10 so the function uses a technique called 9 platform invoking to call the native Win32 8 API. The benefit of this over the some other 7 solutions for PowerShell is that it supports 6 the PowerShell pipeline so you can pipe 5 a list of file paths or System.IO.FileInfo objects to the 4 function. The function also doesn't have 3 any external dependencies and actually deletes 2 the alternate data stream instead of just 1 deleting it's contents.


Score: 0

I'll have to amend @Mike 's answer: this 2 won't work if there are spaces in $_.FullName (e.g. like 1 in "C:\Program Files") so it has to be:

get-childitem -rec | % { cmd /c "echo.>""$($_.FullName)"":Zone.Identifier" }
Score: 0

I haven't seen any answer yet that seems 6 to use the proper powershell cmdlets to 5 do this.

Here we can find DLLs in the current 4 folder that contain the zone.identifier:

Get-Item -Path .\*.dll -stream * | where {$_.Stream -eq "Zone.Identifier" }

Here 3 we zap just only the unwanted streams, unlike 2 some answers above that might damage other 1 streams:

Remove-Item  -Path .\*.dll -stream Zone.Identifier
Score: 0

If you are using PowerShell 3.0 or above 16 vesion, Unblock-file PowerShell cmdlet should solve 15 this problem with unblocking the file, even 14 though if you don't have unblock button 13 on the file properties window.

The Unblock-File 12 cmdlet lets you open files that were downloaded 11 from the Internet. It unblocks Windows PowerShell 10 script files that were downloaded from the 9 Internet so you can run them, even when 8 the Windows PowerShell execution policy 7 is RemoteSigned. By default, these files 6 are blocked to protect the computer from 5 untrusted files.

Just open the powerShell 4 window and follow below syntax. To find 3 more information about the syntax go to 2 here

Example :

unblock-file -path C:\Downloads\MyFileName.chm

Unblock file with PowerShell screen shot

Warning: Do not unblock unsecure 1 files.

Score: 0

If you server does not have Powershell > v3 2 ($PSVersionTable.PSVersion.Major -ge 3). Then 1 use good old reliable DOS:

for /f "tokens=*" %f in ('dir /b *.*') do echo.>"%f":Zone.Identifier 
Score: 0

You can search for blocked files like this:

get-item * -stream zone*

Then 3 to unblock the files, pipe that to remove-item 2 or "rm" to delete the zone.identifier streams:

get-item * -stream zone* | Remove-Item

In 1 case you want recursive search:

get-childitem -recurse | get-item -stream zone*

More Related questions