This topic contains 3 replies, has 2 voices, and was last updated by
April 27, 2016 at 7:35 am #38304
Hi again, so here's a new one, I have a variable that looks like something like this:
column1 column2 column3 column4
a1 b1 c1 d1
a1 b2 c1 d1
a1 b3 c1 d1
a2 b3 c1 d1
a2 b4 c1 d1
a2 b3 c1 d1
a3 b5 c1 d1
a3 b6 c1 d1
a3 b7 c1 d1
a4 b5 c1 d1
I'm trying to create a new variable with just columns 1 and 2 while preserving the order in in the columns, in other words i want to make sure that it will look something like this:
I've already tried:
$a = @()
$testdata = New-Object psobject
$testdata | Add-Member -MemberType NoteProperty -Name Column1 -Value $data.column1
$testdata | Add-Member -MemberType NoteProperty -Name Column2 -Value $data.column2
$a += $testdata
However, instead of getting two nice columns, i get:
Furthermore, once i get the output in desired format, i need to remove duplicates based on column 1, so something like this should be the end result:
I haven't gotten to this part yet myself, since i've been banging my head against the wall on the first part.
Thanks in advance!
April 27, 2016 at 7:38 am #38305
ugh, my formatting got all screwed up :-/
April 27, 2016 at 7:41 am #38306KeymasterTopics: 13Replies: 4872Points: 1,811Rank: Community Hero
$new = $old | Select-Object -Prop Column1,Column2
And you might look further into the -Unique parameter of Select-Object to see if that would be helpful.
April 27, 2016 at 7:48 am #38307
Well, now I feel stupid... this is just way too easy... thank you
The topic ‘create new variable with data from an existing variable’ is closed to new replies.