Contact Info

Crumbtrail » Administration » Powershell » Powershell 1.0 » Get-Unique

Get-Unique - Powershell 1.0 CmdLet

Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. It is designed for system administrators, engineers and developers to control and automate the administration of Windows and applications.

More than hundred command-line tools (so called "cmdlets") can be used to perform system administration tasks and Windows Management Instrumentation (WMI). These cmdlets are easy to use, with standard naming conventions and common parameters, and standard tools for piping, sorting, filtering, and formatting data and objects.


Get the unique items in a collection


       A command/expression/variable that returns the object(s)
      (will treat as a single collection)
       Treat the data as a string, not an object.
       Use this parameter to find the unique values of object properties
       e.g. file names.
       For a collection of objects of the same type, Get-Unique will
       returns just one (the first). 
       Return only one object of each type.

       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Sort an array of integers, and display the unique values:

PS C:\>2,4,6,8,2,64,4,2,99,3 | sort-object | Get-Unique

List every folder on the C: drive that contains one or more .xls files:

PS C:\>gci C:\ -include *.xls -recurse |foreach {$_.directoryName} | get-unique

for more examples:

PS C:\>help get-unique -detailed