我设置了一个变量$ec2-instance = GetEC2Instance
,它返回的内容类似于...
GroupNames : {}
Groups : {}
Instances : {somekey}
OwnerId : 11111111
RequesterId :
ReservationId : r-111111111
我想做的只是列出EC2实例的名称。我知道“名称”是一个标记,但不确定如何在PowerShell中捕获。
答案 0 :(得分:0)
Get-EC2Instance
返回实例列表,您可以遍历该列表并按如下方式获取Name标记的值:
ForEach($i in (Get-EC2Instance).Instances) {
($i.Tags | ? { $_.Key -eq "Name"} | select -expand Value)
}