Get AWS EC2 Instances with Security Groups assigned using PowerShell

Problem:

How do I list all EC2 instances in AWS and show assigned security groups?

Solution:

Get-EC2Instance `
             |%{ $_.RunningInstance } `
             | Select-Object InstanceId,SecurityGroups,@{Name='TagValues'; Expression={($_.Tag |%{ $_.Value }) -join ','}}

Leave a Reply

Your email address will not be published. Required fields are marked *