Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PowerShell Lambda Script
#Requires -Modules @{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.343.0'}
$rulesRemoved = 0
Get-EC2SecurityGroup | ForEach-Object -Process {
$securityGroupId = $_.GroupId
$_.IpPermission | ForEach-Object -Process {
if($_.ToPort -eq 3389) {
Write-Host "Found open RDP port for $securityGroupId"
Revoke-EC2SecurityGroupIngress -GroupId $securityGroupId -IpPermission $_
Write-Host "Removed open RDP port for $securityGroupId"
Write-Host "Scan complete and removed $rulesRemoved EC2 security group ingress rules"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.