Technical Anshu
Tutorials Blog
📂 Bulk Blocking

Block All Programs in a Folder from Internet PowerShell Script

A software folder contains fifteen .exe files — the main program, helpers, updaters, tools. Blocking them one by one through the wizard is an afternoon gone. Honest answer first: the firewall cannot block a folder. But a short PowerShell loop can create all fifteen rules for you.

✍️ Technical Anshu🪟 Windows 10 / 11⏱️ 3 minute script
🎥 The video blocks one app at a time — this guide scales the same idea to a whole folder

Let us be straight before any commands: Windows Firewall has no "block this folder" option. A program rule names one file, always. Anyone promising a folder rule is selling something. The real solution is automation — a PowerShell loop that finds every .exe in the folder and creates one properly named rule per file. It takes longer to read this page than to run the script.

Administrator: Windows PowerShell
Get-ChildItem -Path $folder -Filter *.exe -Recurse | ForEach-Object { New-NetFirewallRule -DisplayName ("BlockFolder-" + $_.Name) ... } BlockFolder-ToolA.exe BlockFolder-ToolB.exe BlockFolder-Updater.exe
One loop, one rule per exe — each named with the same prefix so cleanup is one command too.
1

Why a Script and Not a Setting

Every firewall program rule stores one program path. There is no wildcard like C:\Apps\* and no folder scope for programs — the GUI will not even accept it. That design is actually sensible: Windows always knows exactly which file a rule governs. The cost is manual work for multi-file apps, and a loop pays that cost once.

2

Run the Loop — One Rule per Exe

Open PowerShell as administrator, paste this block, and change only the folder path in the first line:

$folder = "C:\Program Files\MyApp"

Get-ChildItem -Path $folder -Filter *.exe -Recurse | ForEach-Object { New-NetFirewallRule -DisplayName ("BlockFolder-" + $_.Name) -Direction Outbound -Program $_.FullName -Action Block }

  1. -Recurse includes subfolders — remove it if you want only the top folder
  2. Every rule gets the prefix BlockFolder- — this matters for cleanup later
  3. Each rule appears in PowerShell output as it is created; a red error for one file does not stop the rest
3

Verify a Few Rules Landed

Open wf.msc → Outbound Rules and sort by name. You should see your BlockFolder- rules in a neat block, one per file. Spot-check two things: the count roughly matches the number of .exe files in the folder, and one rule's program path (double-click → Programs and Services) is a real full path.

4

Cleanup and the Update Trap

Because every rule shares a prefix, removing them all is one command in administrator PowerShell:

Get-NetFirewallRule -DisplayName "BlockFolder-*" | Remove-NetFirewallRule

And the honest trap to remember: this is a snapshot. Files the app adds later — especially a new version installed into the same folder — are not covered until you run the loop again. If the app escapes after an update, re-run the script; it simply adds rules for the new files alongside the old ones.

🔴 Run it as administrator. In a normal PowerShell window every New-NetFirewallRule line fails with access denied — and the loop cheerfully continues to the end, leaving you with zero rules and a page of red text.

🎥 Watch the Complete Video

Watch the video for the single-app method first — this script is that same rule, written fifteen times by a loop.

▶️ Watch Full Video
❓ Common Questions (FAQ)

How many rules can Windows Firewall handle?

Far more than this. Offices run thousands of rules. A folder with dozens of exes adds a negligible load — do not worry about performance here.

The folder is on another drive or a portable app folder. Does it still work?

Yes. The loop does not care where the folder lives — give the full path, including portable and USB locations. Note that a USB drive letter can change, which changes paths and breaks the rules.

Can I block only outbound and still let the LAN work?

Yes — combine this with the scoped rule trick in this series: instead of plain rules, scope the block to public internet addresses only. The loop creates the rules; the scope ranges are added on each rule's Scope tab or via remoteip in the command.

This guide is based on the Technical Anshu video Block Internet Access for Any Application in Seconds • Stuck on any step? Ask in the video comments — you will get a reply there 🙏