Author Posts

April 27, 2016 at 7:35 am

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:
column1 column2
a1 b1
a1 b2
a1 b3
a2 b3
a2 b4
a2 b3
a3 b5
a3 b6
a3 b7
a4 b5

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:
Column1 Column2
——- ——-
{a1,a1,a1,a2,... {b1,b1,b2,b3,...

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:
column1 column2
a1 b1
a1 b2
a1 b3
a2 b3
a2 b4
a3 b5
a3 b6
a3 b7
a4 b5
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

ugh, my formatting got all screwed up :-/

April 27, 2016 at 7:41 am

$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

Well, now I feel stupid... this is just way too easy... thank you