Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unblock a file with PowerShell?

I am trying to have PowerShell unblock a file in Win2K8 R2.

Does anyone have a pointer as to the syntax?

like image 656
Daniel Elliott Avatar asked Oct 24 '09 09:10

Daniel Elliott


People also ask

How do you check if a file is blocked PowerShell?

One of these is the Unblock-File cmdlet. You can test if a file is blocked by right clicking the file and looking at its properties – it will have an Unblock button at the bottom right of the dialog.

How do I unblock a group of files?

You can check the box (in Windows 10) or click the Unblock button (in Windows 7/8) to unblock the file. However, if you have multiple files, you cannot select more than one and view the properties to unblock all of the files at once. Instead, you will have to check each file separately and unblock them one at a time.


2 Answers

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


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

H:\Downloads> more < test.exe:Zone.Identifier [ZoneTransfer] ZoneId=3 

You can find them using dir /r on Windows Vista and 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 of that by overwriting it (using output redirection, this time):

echo.>myDownloadedFile.exe:Zone.Identifier 

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

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

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

That works from PowerShell as well.

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

streams -d myDownloadedFile.exe 

does work as well.

like image 173
Joey Avatar answered Oct 07 '22 16:10

Joey


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

like image 32
Jaykul Avatar answered Oct 07 '22 17:10

Jaykul