Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 34890

PowerTip: Find Unique Types with PowerShell

$
0
0

Summary: Learn an easy command to help find unique types with Windows PowerShell.

Hey, Scripting Guy! Question How can I filter different types of objects from a command so that I have an example of each unique type?

Hey, Scripting Guy! Answer 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

 


Viewing all articles
Browse latest Browse all 34890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>