whorsfall
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:
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.
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
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:
Open in new window
HTH
Rainer