Unblock Files Powershell | Recursively
unblock-all "C:\Downloads" This feature is useful for safely handling downloaded files that Windows marks with an alternate data stream (Zone.Identifier) to indicate they came from the internet.
Write-Host "Scanning: $targetPath" -ForegroundColor Cyan
$extensions = $typeFilters[$Filter]
# Clear or create log "=== Recursive Unblock Log - $(Get-Date) ===" # Basic usage - unblock everything in current folder and subfolders Unblock-FilesRecursively Specify a different path Unblock-FilesRecursively -Path "C:\Downloads" Only unblock PowerShell scripts and executables Unblock-FilesRecursively -Path "D:\Projects" -IncludeExtensions @("ps1", "exe") Preview what would be unblocked without actually doing it Unblock-FilesRecursively -WhatIf Advanced version with logging and progress Invoke-RecursiveUnblock -Path "C:\Users$env:USERNAME\Downloads" -Filter "Executables" -ShowProgress With confirmation prompt Invoke-RecursiveUnblock -Path "." -WhatIf Quick Alias for Frequent Use Add to your PowerShell profile:
foreach ($file in $files) try # Check if file has zone identifier (downloaded from internet) $stream = $file.GetAccessControl() $hasZoneId = (Get-Item $file.FullName -Stream * -ErrorAction SilentlyContinue catch Write-Warning "Failed to unblock: $($file.FullName) - $_" recursively unblock files powershell
# Get all files recursively $files = Get-ChildItem -Path $targetPath -File -Recurse -ErrorAction SilentlyContinue
Write-Host "`nCompleted! Unblocked $unblockedCount files." -ForegroundColor Cyan # Unblock all files in current directory and subdirectories Get-ChildItem -Recurse | Unblock-File -ErrorAction SilentlyContinue Or more explicitly for files only Get-ChildItem -File -Recurse | Unblock-File Advanced Version with Logging and Progress function Invoke-RecursiveUnblock [CmdletBinding(SupportsShouldProcess=$true)] param( [Parameter(Mandatory=$false)] [string]$Path = ".", [Parameter(Mandatory=$false)] [string]$LogPath = "$env:TEMP\unblock-log.txt", [Parameter(Mandatory=$false)] [ValidateSet("All", "Executables", "Scripts", "Archives")] [string]$Filter = "All", [Parameter(Mandatory=$false)] [switch]$ShowProgress ) unblock-all "C:\Downloads" This feature is useful for safely
$unblockedCount = 0