I've written this PowerShell script to automatically block executables inside a folder in Windows Firewall
$currentdir = get-Location
cd $currentdir
function FirewallBlock {
param ($exes)
$exes | ForEach-Object { New-NetFirewallRule -DisplayName "$_.name inbound" -Direction Inbound -Action Block -Profile Any -Program $_.DirectoryName }
$exes | ForEach-Object { New-NetFirewallRule -DisplayName "$_.name outbound" -Direction Outbound -Action Block -Profile Any -Program $_.DirectoryName }
}
$programs = dir -Recurse *.exe
FirewallBlock ($programs)
Added it to the old style context menu by creating 2 registry keys here:
Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\Firewall
and here
Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\Firewall\command
Firewall key has the default name and value of "Firewall Block Programs"
command key has the default name and string value of
powershell -command "Start-Process pwsh.exe -ArgumentList '-file C:\Users\UserName\OneDrive\Desktop\Firewall.ps1' -Verb runAs"
How can I add this context menu option to the new modern context menu style in Windows 11?
so far I found this but couldn't figure out if I really have to create a program out of this simple PowerShell script in order to add it there or not.