Skip to content

Instantly share code, notes, and snippets.

@Sam-Martin
Created July 5, 2017 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sam-Martin/c72952e39c2f4508ce4cff0ecd8f6f82 to your computer and use it in GitHub Desktop.
Save Sam-Martin/c72952e39c2f4508ce4cff0ecd8f6f82 to your computer and use it in GitHub Desktop.
Add WinRM to all SecurityGroups that have RDP
$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