![](/img/trans.png)
[英]How can I know the Name of the “IAM role” attached to EC2 using PowerShell from EC2 Instance itself?
[英]Only list name of EC2 using Powershell
我设置了一个变量$ec2-instance = GetEC2Instance
,这返回类似...
GroupNames : {} Groups : {} Instances : {somekey} OwnerId : 11111111 RequesterId : ReservationId : r-111111111
我想做的只是列出EC2实例的名称。 我知道“名称”是一个标记,但不确定如何在PowerShell中捕获。
Get-EC2Instance
返回实例列表,您可以遍历该列表并按如下方式获取Name标记的值:
ForEach($i in (Get-EC2Instance).Instances) {
($i.Tags | ? { $_.Key -eq "Name"} | select -expand Value)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.