Created
July 5, 2017 14:11
-
-
Save Sam-Martin/c72952e39c2f4508ce4cff0ecd8f6f82 to your computer and use it in GitHub Desktop.
Add WinRM to all SecurityGroups that have RDP
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
$Ips = @("192.168.1.1") | |
foreach($Region in $(Get-AWSRegion).Region){ | |
$SecurityGroupsContainingRDP = Get-EC2SecurityGroup -region $Region| ?{$_.ippermission.FromPort -eq 3389} | |
Foreach($SecurityGroup in $SecurityGroupsContainingRDP){ | |
Write-Verbose "Adding WinRM to $($SecurityGroup.GroupID)" | |
try{ | |
Grant-EC2SecurityGroupIngress -GroupId $SecurityGroup.GroupId -region $Region -IpPermission @{IpProtocol="TCP";FromPort=5985;ToPort=5986;IPRanges=$IPs} | |
}catch{ | |
if($_.exception.message -like "*already exists*"){ | |
Write-Verbose "`tRule already exists" | |
}else{ | |
Write-Error $_.exception.message | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment