tryin to get ec2volume mounted ec2instances

0

I am trying to get the volumes mounted on my ec2instance

get-ec2volume -filter @{name='attachment.instance-id'; values="*"} |? {$_.Attachments.InstanceId -eq 'i-xxxxxxxxxxxx'}

but I also want to get the Tag with Name as well.

any idea?

drago
질문됨 2년 전202회 조회
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
AWS
Taka_M
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠