具有多个值显示输出 [英] Displaying output with multiple values

查看:101
本文介绍了具有多个值显示输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Get-EC2Instance |%{ $_.RunningInstance } | 
    select-object InstanceId,LaunchTime,@{Name='Value'; Expression={$_.Tag.Value} }, @{Name='Key'; Expression={$_.Tag.Key} }

每个价值和重点有多个值,你可以在截图中看到。如何改写code所以输出可以是这样的:

Each Value and Key have multiple values as you can see in the screenshot. How to rewrite the code so the output can look like:

推荐答案

下面是一个解决方案;这不是最优雅的,但希望解决您的问题:

Here's one solution; it's not the most elegant, but hopefully solves your problem:

为您的使用案例

Get-EC2Instance | `
    %{ 
        $x = $.RunningInstance;
        $x.Tag | select-object 
             @{Name="InstanceId"; Expression={$x.InstanceId}}
            ,@{Name="LaunchTime"; Expression={$x.LaunchTime}}
            ,@{Name="Value";      Expression={$_.Value}}
            ,@{Name="Key";        Expression={$_.Key}};
    } 

简单的演示

cls
$x = @(
     (New-Object –TypeName PSObject –Prop @{Name='one';List=@('a','b','c');})
    ,(New-Object –TypeName PSObject –Prop @{Name='two';List=@('d','e','f');})
    ,(New-Object –TypeName PSObject –Prop @{Name='three';List=@('g','h','i');})
    ,(New-Object –TypeName PSObject –Prop @{Name='four';List=@('j','k','l');})
    ,(New-Object –TypeName PSObject –Prop @{Name='five';List=@('m','n','o');})
)

#show what the preparation code produced:
#$x | select Name, List

#show the output we're after
$x | %{$n=$_.Name; $_.List | select @{Name="Name";Expression={$n}},@{Name="ListValue";Expression={$_}}}

这篇关于具有多个值显示输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆