Link to home
Start Free TrialLog in
Avatar of whorsfall
whorsfallFlag for Australia

asked on

Powershell - Select-Object -Unique vs Group-Object

Hi,

I have the following problem with powershell.

I have a list of strings call it $machine_list which
I know there are duplicates.

The following  code produces the following output:

$machine_list.count -- 15375

$a = $machine_list | Select-Object -Unique
$a.Count -- 12134

$b = $machine_list | Group-Object -NoElement
$b.Count -- 12082

Open in new window


I am trying to get a unique list and looking at different
ways of doing it.

So in my example above why are the counts different?
Should they not be the same - $a.Count -eq $b.Count?

I am hoping somebody can explain this in more detail to me.

Also is there a way I can compare the results to see how they
differ? (Comparing $a with the Name Values of $b).

Thanks,

Ward.
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Hi Ward,
could you provide the machine list? How did you create this list of strings?

As far as I can remember, the unique command needs to have the list sorted.
What does this return:
$a = $machine_list | Sort-Object | Select-Object -Unique

Open in new window


HTH
Rainer
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial