Skip to content

Instantly share code, notes, and snippets.

@dsect
Created September 26, 2019 14:00
Show Gist options
  • Select an option

  • Save dsect/f01d8186c96c7d0be02be8547d247c1b to your computer and use it in GitHub Desktop.

Select an option

Save dsect/f01d8186c96c7d0be02be8547d247c1b to your computer and use it in GitHub Desktop.
$Ec2Instances = @()
$Instances = (Get-EC2Instance -Filter `
@(
@{name = "tag:MyFirstTag"; values = "FirstTagValue" },
@{name = "tag:MySecondTag"; values = @("SecondTagValue1"; "SecondTagValue2") }
)
).Instances
foreach ($Instance in $Instances) {
$Ec2Instance = [pscustomobject]@{
Name = ($Instance.Tag | Where-Object { $_.Key -eq 'MyFirstTag' }).Value
Environment = ($Instance.Tag | Where-Object { $_.Key -eq 'MySecondTag' }).Value
}
$Ec2Instances += $Ec2Instance
# Do per-instance operations
$Instance
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment