Skip to content

Instantly share code, notes, and snippets.

@st1vms
Created January 22, 2026 20:07
Show Gist options
  • Select an option

  • Save st1vms/bcafc3cf66765b22801335e8b256dbb0 to your computer and use it in GitHub Desktop.

Select an option

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
!WF Block EC2 Out
$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