I am trying to have PowerShell unblock a file in Win2K8 R2.
Does anyone have a pointer as to the syntax?
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.
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.
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.
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 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With