1개 답변
- 최신
- 최다 투표
- 가장 많은 댓글
0
What is the expected output you are looking for? Tags are returned as part of Get-EC2Volume
command output. If you are trying to specifically return a list of tags for a particular EBS volume based on an EC2 instance ID, then you can try something like this:
# Print Instance ID and Tags for a particular EC2 instance's EBS volume
$tagKeyValue = ""
get-ec2volume -filter @{name = 'attachment.instance-id'; values = "*" } | % {
if ($_.Attachments.InstanceId -eq '<instance id>') {
# Concatenate tags in a string (key:value;key2:value2...)
if ($_.Tags.Count -gt 0) {
$counter = 0
while ($counter -lt $_.Tags.Count) {
$tagKeyValue += ("{0}:{1};" -f $_.Tags[$counter].Key, $_.Tags[$counter].Value)
write-host $counter
$counter++
}
}
@{
InstanceId = $_.Attachments.InstanceId
Tags = $tagKeyValue
}
}
}
Sample output
Name Value
---- -----
Tags Name:test.local;test:test;
InstanceId i-xxxxxxxxxxxxxxxxxxxxxxx
답변함 2년 전
관련 콘텐츠
- AWS 공식업데이트됨 8달 전