Solved

Powershell: Issues with Get-unique

Posted on 2010-11-15
4
932 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

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

Expert Comment

by:KenMcF
ID: 34138691
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
ID: 34138711
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
ID: 34139308
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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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