Find unique entries with PowerShell

Find unique values with PowerShell

John Savill

March 11, 2017

1 Min Read
Find unique entries with PowerShell

Q. How can I find only unique entries in PowerShell?

A. I recently had a very large array of users who were in various offices and I had to first create OUs for each office so needed to first find all the offices out of the hundreds of user records. Fortunately PowerShell can do this very simply.

$Offices = $Users | Select-Object OfficeCode, OfficeName, Region | Sort-Object OfficeCode | Get-Unique -AsString

In this example the OfficeCode, OfficeName and Region properties are extracted from each user. These are then sorted by the OfficeCode and then only the unique entries output. This is then saved to variable $Offices which I used to enumerate through and create the actual offices.

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like