Skip to content

Instantly share code, notes, and snippets.

@avvi00
Created April 21, 2016 12:28
Show Gist options
  • Save avvi00/9525f5b2ba5956c692c30274c755d3cc to your computer and use it in GitHub Desktop.
Save avvi00/9525f5b2ba5956c692c30274c755d3cc to your computer and use it in GitHub Desktop.
Get a collection of ec2 instance names (from tag) with associated security groups
Get-EC2Instance |
Select -ExpandProperty Instances |
Select -Property @{
Name='InstanceId'
Expression={$_.InstanceId}
},
@{
Name='SecurityGroups'
Expression = {$_.SecurityGroups | Select -ExpandProperty GroupId}
},
@{
Name='TagName'
Expression={$_.Tags | ? {$_.Key -eq 'Name'} | Select -ExpandProperty Value }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment