0

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
asked Jun 24, 2015 at 1:54
3
  • Are Key and Value parallel lists (same numerical index in both is a matched pair)? Commented Jun 24, 2015 at 2:10
  • correct Etan. they are parallel lists. Each key has one value. Commented Jun 24, 2015 at 2:19
  • How is this different from your last question? stackoverflow.com/questions/31015310/… Commented Jun 24, 2015 at 3:23

2 Answers 2

1

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

0

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.