简体   繁体   中英

Only list name of EC2 using Powershell

I set an a variable $ec2-instance = GetEC2Instance and this returns something like...

GroupNames : {} Groups : {} Instances : {somekey} OwnerId : 11111111 RequesterId : ReservationId : r-111111111

What I'm trying to do is list just the name of the EC2 instance. I know, "name" is a tag but not sure how to capture in PowerShell.

Get-EC2Instance returns a list of Instances, you can iterate over that list and grab the value of the Name tag like this:

ForEach($i in (Get-EC2Instance).Instances) {
   ($i.Tags | ? { $_.Key -eq "Name"} | select -expand Value)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM