Unblock Files Using PowerShell v3 “Unblock-File” cmdlet

Unblock Files Using PowerShell v3 “Unblock-File” cmdlet
You might have encountered some situations like when we download a file from the internet we would not able to run it until we unblock that file in its downloaded file properties.Here’s an example of a file I downloaded from internet, even though I  have my PowerShell Sessions Execution policy set to “Remote Signed” it would still fail to load the script and I would need to manually access the file properties and unblock that file.

Now PowerShell V3 offers us a new cmdlet to tackle these situations with a new cmdlet called as  “Unblock-File”

It Helps in unblocking files which are downloaded from internet.

By default, these files are blocked to protect the computer from untrusted files which might contain spyware etc.

Internally, the Unblock-File cmdlet removes the Zone.Identifier property to indicate that it was downloaded from the Internet.

Now let me get details regarding the file with identified stream as “Zone.Identifier”

Get-Item -Stream "Zone.Identifier" 'C:UsersAdministratorDownloadsEnable PS Remoting.ps1' | fl *

 

Now let me Unblock the file using Unblock-File and rerun Get-Item with stream property.

 

So above we can see that the stream property returned in an error, we can suppress the error by setting ea=silentlycontinue

Now if i again go and check the properties of the file i do see that its unlocked

I can further automate unblocking of all files present in my c:downloads directory by use powershell pipelining

Get-Item c:usersadministratordownloads* | Unblock-File

 

Share this post

Post Comment