I cant figure out how this works...please help...
$output = Get-EC2Instance |%{ $_.RunningInstance } | select-object InstanceId,@{Name='Key'; Expression={$_.Tag.Key} },@{Name='Value'; Expression={$_.Tag.Value} }
This command displays : enter image description here
I run the second command below which splits "Key" (Each instanceId has multiple Keys associated to it. Each key has its associated value):
$output | %{$n=$_.InstanceId; $_.Key | select @{Name="InstanceID";Expression={$n}},@{Name="Key";Expression={$_}}}
The output is enter image description here
How to modify the second command to include "Value
" column (each key has a associated value)?
TheMadTechnician
36.4k3 gold badges47 silver badges62 bronze badges
2 Answers 2
I "think" you want this:
$output | Foreach {$vals=$_.Value; $n=$_.InstanceId; $i = 0; $_.Key |
Select @{Name="InstanceID";Expression={$n}},
@{Name="Key";Expression={$_}},
@{Name="Value";Expression={$vals[$i++]}}}
answered Jun 24, 2015 at 4:35
Comments
I'am not sure to follow but if I understand :
$a =$output[0]
$a["one_key"] -> "One_Value"
Then
$output | %{$n=$_; $_.Key | select @{Name="InstanceID";Expression={$($n.InstanceId)}},@{Name="Key";Expression={$_}},@{Name="Value";Expression={$n[$_]}}}
I can't test it ans it's very early in the morning so be lenient.
answered Jun 24, 2015 at 3:25
Comments
lang-bash
Key
andValue
parallel lists (same numerical index in both is a matched pair)?