Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell: Issues with Get-unique

Posted on 2010-11-15
4
Medium Priority
?
936 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 1000 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

Introducing the WatchGuard 420 Access Point

WatchGuard's newest access point includes an 802.11ac Wave 2 chipset, providing the fastest speeds for VoIP, video and music streaming, and large data file transfers. Additionally, enjoy the benefits of strong security as the 3rd radio delivers dedicated WIPS protection!

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
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…

721 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