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.