Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell to unblock all the files in a folder

Trying to make a .bat I can drop in a folder, when run it will unblock all the files in that folder...

@ECHO OFF
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {get-childitem '%~dp0' | unblock-file}"
EXIT

...keeps telling me "The term 'unblock-file' is not recognized as the name of a cmdlet..." no matter how I try to format it, where am I going wrong?

I'm trying to do this so I can just copy the .bat to the folder (and NOT have to copy a .bat and .ps1) so I thought a 1-line powershell "call" was the way to go?

like image 559
notAduck Avatar asked Apr 29 '15 03:04

notAduck


2 Answers

The unblock-file command is available from Powershell 3.0. Upgrade your PowerShell and script should work

like image 185
Piotr Stapp Avatar answered Sep 22 '22 10:09

Piotr Stapp


Tested and working:

dir -r | unblock-file

Unblocks everything from the current directory recursively

like image 28
Hello World Avatar answered Sep 20 '22 10:09

Hello World