Recursively Unblock Files Powershell (2026)
# Get all files recursively $files = Get-ChildItem -Path $targetPath -File -Recurse -ErrorAction SilentlyContinue
# Get files $allFiles = Get-ChildItem -Path $Path -File -Recurse -ErrorAction SilentlyContinue
$total = $files.Count $processed = 0 $unblocked = 0 $results = @() recursively unblock files powershell
$unblockedCount = 0
# Define file type filters $typeFilters = @ "Executables" = @(".exe", ".msi", ".bat", ".cmd", ".ps1", ".vbs", ".js") "Scripts" = @(".ps1", ".bat", ".cmd", ".vbs", ".js", ".py", ".rb", ".pl") "Archives" = @(".zip", ".7z", ".rar", ".tar", ".gz") "All" = @() # Get all files recursively $files = Get-ChildItem
# 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:
if ($extensions.Count -gt 0) $files = $allFiles else $files = $allFiles ".js") "Scripts" = @(".ps1"
# Add to $PROFILE function ub Get-ChildItem -Path $args[0] -File -Recurse Set-Alias -Name unblock-all -Value ub Then simply use: