Created
January 22, 2026 20:07
-
-
Save st1vms/bcafc3cf66765b22801335e8b256dbb0 to your computer and use it in GitHub Desktop.
Powershell script to configure Windows Firewall in order to block all EC2 outbound traffic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| !WF Block EC2 Out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $awsIps = Invoke-RestMethod -Uri "https://ip-ranges.amazonaws.com/ip-ranges.json" | |
| $ec2Ranges = $awsIps.prefixes | Where-Object { $_.service -eq "EC2" } | Select-Object -ExpandProperty ip_prefix | |
| New-NetFirewallRule -DisplayName "Block All AWS EC2 Outbound" ` | |
| -Direction Outbound ` | |
| -Action Block ` | |
| -RemoteAddress $ec2Ranges |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment