• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 941
  • Last Modified:

Powershell: Issues with Get-unique

I have two questions regarding the get-unique cmdlet.

One:
If I have a txt file with 100 computer names with duplicates I want the duplicates to be removed.
I have the following lines but they do not remove duplicates properly.

[array]$colComputers = get-content "c:\temp\ISP\listAllComputers.txt" | Sort-Object | Get-Unique

no duplicates are removed. Am I using this right?

Question two:
Is there a way to invoke the get-unique where it does not care or check for uppercase or lowercase?
For example with the following txt file entries:
apple
pear
APPLE
ApPle

there will be only two ouputs
apple
pear

thanks in advance,
K
0
chad
Asked:
chad
  • 2
1 Solution
 
daveTechSearchCommented:
try this instead:
[array]$colComputers = get-content "c:\temp\ISP\listAllComputers.txt" | Sort-Object -unique
0
 
KenMcFCommented:
I do not think you can account for different case. You could create an array and change all computer account to upper or lower case so they all match then select the unique ones.


$cmps = @()
gc "c:\temp\ISP\listAllComputers.txt" | %{$cmps += $_.toupper()}
$cmps | sort | get-unique
0
 
KenMcFCommented:
The way daveTechSearch mentioned, is much easier. I forgot that the switch in select was not case sensitive.
0
 
chadAuthor Commented:
Thanks Dave,

Using that technique did solve both concerns.
I had a feeling I may end up having to go the route you KenMcF mentioned.

Thank you both,
K

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now