How to unblock files

Issue

Depending on the Execution-Policy script files from the web might be blocked by Windows. This results in various errors. If a module file is blocked you get errors that some commandlets do not exist. If a script file is blocked you might get an error that the script cannot be executed.

How to check if a file is blocked

  • Right click the file
  • Select Properties
  • In the "General" tab look for an "Unblock" button
  • If there is no "Unblock" button the file is not blocked

Unblocking a single file

  • Press the unblock button to unblock a single file. If you do this for a zip file, all the files in it will be unblocked

Unblocking multiple files

  • If you already unpacked the files you can use the Unblock-File commandlet to unblock them. This requires at least Powershell 3
  • If you are using this make sure you are only unblocking script files that are safe to use
    • Example that unblocks all the ps1 files in C:\TEMP and its subfolders:
      Get-ChildItem -Path "C:\TEMP" -Filter "*.ps1" -Recurse | Unblock-File 

Links