Skip to content

Instantly share code, notes, and snippets.

@lantrix
Created October 31, 2014 08:11
Show Gist options
  • Select an option

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

Select an option

Save lantrix/c01d9235500072eaff9d to your computer and use it in GitHub Desktop.
Add new tags to AWS EC2 instances found by tag filter
#get instances with specific tag
$tagFilter1 = New-Object Amazon.EC2.Model.Filter
$tagFilter1.Name = "tag:Environment Name"
$tagFilter1.Value.Add("MyEnv")
$instances = Get-EC2Instance -Filter @($tagFilter1)
#New or update tag on instances
foreach ($i in $instances.Instances) {
New-EC2Tag -ResourceId $i.InstanceId -Tags @(@{ Key="YourTagName"; Value="YourTagValue" })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment