Summary: Learn an easy command to help find unique types with Windows PowerShell.
How can I filter different types of objects from a command so that I have an example of each unique type?
If you use the Get-Unique cmdlet with no switched parameters, many of the objects returned are the same type (the DirectoryInfo objects in this example):
PS C:\> Get-ChildItem | Get-Unique
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 6/17/2013 1:00 PM Afolder
d---- 6/17/2013 1:00 PM Bfolder
d-r-- 6/2/2013 10:56 PM data
d---- 3/9/2013 6:35 PM DRIVERS
<output truncated>
If you use the Get-Unique cmdlet with the –OnType switch, only one example of each of the type of object returns (a FileInfo object and a DirectoryInfo object in this example):
PS C:\> Get-ChildItem | Get-Unique -OnType
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 6/17/2013 1:00 PM Afolder
-a--- 3/9/2013 7:29 PM 4627788 MSIInstall.log