Recursively Unblock Files Powershell May 2026

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) - $_"

Write-Host "Scanning: $targetPath" -ForegroundColor Cyan recursively unblock files powershell

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 Out-File $LogPath "Path: $Path" Usage Examples # 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

function Unblock-FilesRecursively [CmdletBinding()] param( [Parameter(Mandatory=$false, Position=0)] [string]$Path = ".", [Parameter(Mandatory=$false)] [string[]]$IncludeExtensions = @(), [Parameter(Mandatory=$false)] [switch]$WhatIf ) Position=0)] [string]$Path = "."

# Resolve the path $targetPath = Resolve-Path $Path -ErrorAction Stop

# Add to $PROFILE function ub Get-ChildItem -Path $args[0] -File -Recurse Set-Alias -Name unblock-all -Value ub Then simply use: