Solved

Powershell: Issues with Get-unique

Posted on 2010-11-15
4
927 Views
Last Modified: 2012-05-10
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
Comment
Question by:kabaam
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
daveTechSearch earned 250 total points
Comment Utility
try this instead:
[array]$colComputers = get-content "c:\temp\ISP\listAllComputers.txt" | Sort-Object -unique
0
 
LVL 27

Expert Comment

by:KenMcF
Comment Utility
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
 
LVL 27

Expert Comment

by:KenMcF
Comment Utility
The way daveTechSearch mentioned, is much easier. I forgot that the switch in select was not case sensitive.
0
 
LVL 11

Author Comment

by:kabaam
Comment Utility
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now