Get-ChildItem "C:\scripts" -Filter *.ps1 -Recurse | Unblock-File Set-ExecutionPolicy RemoteSigned -Scope CurrentUser | Task | Command | |------|---------| | Unblock all files in a folder | ls "C:\Folder" -File | Unblock-File | | Unblock recursively | ls "C:\Folder" -File -Recurse | Unblock-File | | Preview changes | Add -WhatIf to any Unblock-File command |
if ($files.Count -eq 0) Write-Host "No files found in $FolderPath" exit
Write-Host "Unblock operation completed on $($files.Count) files." powershell unblock all files in folder
ls "C:\Downloads" -File | Unblock-File Get-ChildItem -Path "C:\Downloads" -File -Recurse | Unblock-File 4. Unblock Only Specific File Types (e.g., .ps1 and .exe ) Get-ChildItem -Path "C:\Downloads" -Recurse -Include *.ps1, *.exe | Unblock-File 5. Dry Run with -WhatIf Get-ChildItem -Path "C:\Downloads" -File | Unblock-File -WhatIf This shows which files would be unblocked without actually changing them. Complete Script Example Save the following as Unblock-Folder.ps1 :
After unblocking, the same command returns nothing. | Consideration | Detail | |---------------|--------| | Administrator rights | Not required for files you own, but may be needed for system-protected locations. | | Security risk | Only unblock files you trust. Malware often arrives via downloads. | | No output by default | Unblock-File is silent. Use -Verbose or -PassThru (not supported) – instead pipe to Select-Object or log manually. | | Wildcards | Unblock-File does not accept wildcards directly in -Path . Always pipe from Get-ChildItem . | | PowerShell version | Requires PowerShell 3.0 or later (Windows 8+/Server 2012+). | Alternative: Remove ADS Manually If you need to unblock without Unblock-File (e.g., older PowerShell), use: Get-ChildItem "C:\scripts" -Filter *
Get-Item "C:\Downloads\file.ps1" -Stream * If Zone.Identifier appears, the file is blocked.
When you download a PowerShell script and see: Complete Script Example Save the following as Unblock-Folder
By using Unblock-File with Get-ChildItem , you can quickly and safely remove web markings from entire folders, saving hours of manual property-tweaking. Always verify the source before unblocking.