• Narrow screen resolution
  • Wide screen resolution
  • Increase font size
  • Decrease font size
  • Default font size
  • default color
  • red color
© Diana Scherff, Amas-Veritas.com

Welcome to Amas Veritas [dot] com

Updates: Media (lyrics) has a new layout. I could never figure out how to lay it out, but it's easier to navigate now. I'm still working on a better duplicate Mamblog mod. I'm trying to make submittions easier but the poetry form died for some reason. Quizzes are also on their way from the old site. Joomla content isn't very code friendly so I'm having to rewrite old code. You can still click on News > AH v21 > Screen if you wish to use the quizzes.
 
Home arrow Tools arrow Windows PowerShell arrow Get-Unique [gu]
Get-Unique [gu] Print E-mail
Written by Diana, on 04-09-2007 02:30
Views 111    
Favoured None

PS C:\Users\Admin> help gu -full

NAME
    Get-Unique

SYNOPSIS
    Returns the unique items from a sorted list.

SYNTAX
    Get-Unique [-inputObject <psobject>] [-asString] [<CommonParameters>]

    Get-Unique [-inputObject <psobject>] [-onType] [<CommonParameters>]


DETAILED DESCRIPTION
    The Get-Unique cmdlet compares each item in a sorted list to the next item, eliminates duplicates, and returns only one instance of each item. The list must be sorted for the cmdlet to work properly.


PARAMETERS
    -inputObject <psobject>
        Accepts input for Get-Unique. Enter a variable that contains the objects or type a command or expression that gets the objects.

        Get-Unique treats the input submitted by using InputObject as a collection; it doesn't enumerate individual items in the collection. Because the collection is a single item, input submitted by using InputObject is always returned unchanged.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?       true (ByValue)
        Accept wildcard characters?  false

    -asString <SwitchParameter>
        Treats the data as a string. Without this parameter, data is treated as an object, so when you submit a collection of objects of the same type to Get-Unique, such as a collection of files, it returns just one (the first). You can use this parameter to find the unique values of object properties, such as the file names.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -onType <SwitchParameter>
        Returns only one object of each type.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".


INPUT TYPE
    any


RETURN TYPE
    any


NOTES


        For more information, type "Get-Help Get-Unique -detailed". For technical information, type "Get-Help Get-Unique -full".

        To sort a list, use Sort-Object. You can also use the Unique parameter of Sort-Object to find the unique items in a list.

        When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

        You can also refer to Get-Unique by its built-in alias, "gu". For more information, see About_Alias.


    ----------------- EXAMPLE 1 -----------------

    C:\PS>$a = $(foreach ($line in get-content C:\Test1\File1.txt) {$line.tolower().split(" ")}) | sort | get-unique

    $a.count


    These commands find the number of unique words in a text file.

    The first command gets the content of the File.txt file. In converts each line of text to lower case and then splits each word onto a separate line at the space (" "). Then, it sorts the resulting list alphabetically (the default), and uses the Get-Unique cmdlet to eliminate any duplicate words. The results are stored in the $a variable.

    The second command uses the Count property of the collection of strings in $a to determine how many items are in $a.





    ----------------- EXAMPLE 2 -----------------

    C:\PS>1,1,1,1,12,23,4,5,4643,5,3,3,3,3,3,3,3 | sort-object | Get-Unique


    This command finds the unique members of the set of integers. The first command takes an array of integers typed at the command line, pipes them to the Sort-Object cmdlet to be sorted, and then pipes them to Get-Unique, which eliminates duplicate entries.





    ----------------- EXAMPLE 3 -----------------

    C:\PS>get-childitem | sort-object {$_.GetType()} |  unique -OnType


    This command uses the Get-ChildItem cmdlet to retrieve the contents of the local directory, which includes files and directories. The pipeline operator (|) sends the results to the Sort-Object cmdlet. The "$_.GetType()" statement applies the GetType method to each file or directory. Then, Sort-Object sorts the items by type. Another pipeline sends the results to Get-Unique. The OnType parameter directs Get-Unique to return only one object of each type.





    ----------------- EXAMPLE 4 -----------------

    C:\PS>get-process | sort-object | select processname | get-unique -asstring


    This command gets the names of processes running on the computer with duplicates eliminated.

    The Get-Process command gets all of the processes on the computer. The pipeline operator passes the result to sort-object, which, by default, sorts the processes alphabetically by ProcessName. The results are piped to the Select-Object cmdlet, which selects only the values of the ProcessName property of each object. The results are then piped to Get-Unique to eliminate duplicates.

    The AsString parameter tells Get-Unique to treat the ProcessName values as strings. Without this parameter, Get-Unique treats the ProcessName values as objects, and returns only one instance of the object, that is, the first process name in the list.






RELATED LINKS
    Select-Object
    Sort-Object


Last update: 04-09-2007 02:30

Published in : Tools, Windows PowerShell

Users' Comments (0) RSS feed comment

No comment posted

Add your comment



mXcomment 1.0.4 © 2007-2009 - visualclinic.fr
License Creative Commons - Some rights reserved
 
< Prev   Next >




Double click any word on this page for a definition.
Using Firefox? Enable definitions by downloading the extension.
Sorry, this feature does not currently work in Opera or Safari.

No Users Online

Statistics

OS: FreeBSD
PHP: 5.2.1
MySQL: 4.1.21-log
Time: 20:07
Caching: Disabled
GZIP: Disabled
Members: 36
News: 2448
Web Links: 39
Visitors: 1443215

Syndicate

Login

Particls