Example 1
Get-EC2Tag -Filter @{Name="resource-type";Values="image"}
Key ResourceId ResourceType Value
--- ---------- ------------ -----
Name ami-0a123b4ccb567a8ea image Win7-Imported
auto-delete ami-0a123b4ccb567a8ea image never
This example fetches the tags for resource-type 'image'
Example 2
Get-EC2Tag | Group-Object resourcetype
Count Name Group
----- ---- -----
9 subnet {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
53 instance {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
3 route-table {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
5 security-group {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
30 volume {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription...}
1 internet-gateway {Amazon.EC2.Model.TagDescription}
3 network-interface {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
4 elastic-ip {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
1 dhcp-options {Amazon.EC2.Model.TagDescription}
2 image {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
3 vpc {Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription, Amazon.EC2.Model.TagDescription}
This example fetches all the tags for all the resources and groups them by resource type
Example 3
Get-EC2Tag -Region eu-west-1 -Filter @{Name="tag:auto-delete";Values="no"}
Key ResourceId ResourceType Value
--- ---------- ------------ -----
auto-delete i-0f1bce234d5dd678b instance no
auto-delete vol-01d234aa5678901a2 volume no
auto-delete vol-01234bfb5def6f7b8 volume no
auto-delete vol-01ccb23f4c5e67890 volume no
This example displays all the resources with tag 'auto-delete' with value 'no' for the given region
Example 4
Get-EC2Tag -Region eu-west-1 -Filter @{Name="tag:auto-delete";Values="no"} | Where-Object ResourceType -eq "instance" | ForEach-Object {New-EC2Tag -ResourceId $_.ResourceId -Tag @{Key="ThisInstance";Value=$_.ResourceId}}
This example obtains all the resources with tag 'auto-delete' with 'no' value and further filters in the next pipe to parse only 'instance' resource types and eventually creates 'ThisInstance' tag for each instance resources with value being the instance id itself
Example 5
Get-EC2Tag -Filter @{Name="resource-type";Values="instance"},@{Name="key";Values="Name"} | Select-Object ResourceId, @{Name="Name-Tag";Expression={$PSItem.Value}} | Format-Table -AutoSize
ResourceId Name-Tag
---------- --------
i-012e3cb4df567e1aa jump1
i-01c23a45d6fc7a89f repro-3
This example fetches tags for all the instance resources as well as 'Name' keys and displays them in a table format