Skip to content

Instantly share code, notes, and snippets.

@lantrix
Created September 18, 2014 05:41
Show Gist options
  • Select an option

  • Save lantrix/c54f71b3ee62bf25b456 to your computer and use it in GitHub Desktop.

Select an option

Save lantrix/c54f71b3ee62bf25b456 to your computer and use it in GitHub Desktop.
Get all AWS instances in certain environment (by Tag) and show Name Tag
#get instances with specific tag and show
$tagFilter1 = New-Object Amazon.EC2.Model.Filter
$tagFilter1.Name = "tag:Environment Name"
$tagFilter1.Value.Add("Test")
$tagFilter2 = New-Object Amazon.EC2.Model.Filter
$tagFilter2.Name = "tag:Name"
$tagFilter2.Value.Add("*")
$instances = Get-EC2Instance -Filter @($tagFilter1,$tagFilter2)
foreach ($i in $instances.Instances) {
$i.InstanceId
$i.tags[$i.tags.Key.IndexOf("Name")] | format-list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment