Overview When you download files from the internet or receive them from external sources, Windows automatically adds an "alternate data stream" (ADS) called the Zone Identifier. This marks files as potentially unsafe, causing PowerShell scripts, executables, and other files to be blocked. The Unblock-File cmdlet in PowerShell removes this restriction. The Basic Command To unblock all files within a specific directory:
Get-ChildItem -Path "C:\YourDirectory" | Unblock-File Or using the alias: powershell unblock all files in directory
# Unblock all downloaded scripts in a project folder $projectPath = "C:\Users\$env:USERNAME\Downloads\ProjectFiles" if (Test-Path $projectPath) Unblock-File -PassThru).Count Write-Host "Successfully unblocked $count files" -ForegroundColor Green else Write-Host "Directory not found" -ForegroundColor Red Overview When you download files from the internet
ls "C:\YourDirectory" | Unblock-File 1. Recursively Unblock All Files in Subdirectories Get-ChildItem -Path "C:\YourDirectory" -Recurse | Unblock-File 2. Unblock Only Specific File Types # Unblock only PowerShell scripts Get-ChildItem -Path "C:\YourDirectory" -Filter *.ps1 -Recurse | Unblock-File Unblock multiple file types Get-ChildItem -Path "C:\YourDirectory" -Include *.ps1, *.exe, *.dll -Recurse | Unblock-File 3. With Error Handling Get-ChildItem -Path "C:\YourDirectory" -Recurse -File | ForEach-Object try Unblock-File -Path $_.FullName -ErrorAction Stop Write-Host "Unblocked: $($_.FullName)" -ForegroundColor Green catch Write-Host "Failed to unblock: $($_.FullName) - $_" -ForegroundColor Red The Basic Command To unblock all files within
# Check current execution policy Get-ExecutionPolicy powershell -ExecutionPolicy Bypass -Command "Get-ChildItem -Recurse | Unblock-File" Alternative Method Using Streams For older PowerShell versions (prior to 3.0) or more granular control: