Tag Archives: Culture

Sort-Object

NAME
    Sort-Object

SYNOPSIS
    Sorts objects by property values.

SYNTAX
    Sort-Object [[-Property] <Object[]>] [-CaseSensitive] [-Culture <string>] [-Descending] [-InputObject <psobject>] [-Unique] [<CommonParameters>]

DESCRIPTION
    The Sort-Object cmdlet sorts objects in ascending or descending order based on the values of properties of the object.

    You can specify a single property or multiple properties (for a multi-key sort), and you can select a case-sensitive or case-insensitive sort. You can also direct Sort-Object to display only the objects with a unique value for a particular property.

PARAMETERS
    -CaseSensitive [<SwitchParameter>]
        Indicates that the sort should be case sensitive. By default, sorting is not case sensitive.

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

    -Culture <string>
        Specifies the cultural configuration to use when sorting.

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

    -Descending [<SwitchParameter>]
        Sorts the objects in descending order. The default is ascending order.

        The Descending parameter applies to all properties. To sort by some properties in
        ascending order and others in descending order, you must specify their property values by using a hash table. For details, see the examples.

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

    -InputObject <psobject>
        Specifies the objects to be sorted.

        When you use the InputObject parameter to submit a collection of items, Sort-Object receives one object that represents the collection. Because one object cannot be sorted, Sort-Object returns the entire collection unchanged.

        To sort objects, pipe them to Sort-Object.

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

    -Property <Object[]>
        Specifies the properties to use when sorting. Objects are sorted based on the values of these properties. Enter the names of the properties. Wildcards are permitted.

        If you specify multiple properties, the objects are first sorted by the first property. If more than one object has the same value for the first property, those objects are sorted by the second property. This process continues until there are no more specified properties or no groups of objects.

        If you do not specify properties, the cmdlet sorts based on default properties for the object type.

        The value of the Property parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:

        — Expression <string> or <script block>
        — Ascending <Boolean>
        — Descending <Boolean>

        Required?                    false
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? true

    -Unique [<SwitchParameter>]
        Eliminates duplicates and returns only the unique members of the collection. You can use this parameter instead of using the Get-Unique cmdlet.

        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, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe the objects to be sorted to Sort-Object.

OUTPUTS
    System.Management.Automation.PSObject
        Sort-Object returns the sorted objects.

NOTES

        Sort-Object sorts objects based on the properties that you specify or the default sort properties for objects of that type.

        If an object does not have one of the specified properties, the property value for that object is interpreted by the cmdlet as NULL and is placed at the end of the sort order.

        When sorting objects, Sort-Object uses the Compare method for each property. If a property does not implement IComparable, the cmdlet converts the property value to a string and uses the Compare method for System.String.

        The Sort-Object cmdlet sorts objects in ascending or descending order based on the values of properties of the object.

        If you sort on a property whose value is an enumeration, Sort-Object sorts the enumeration values in numeric order; it does not sort the enumeration member names. For example, if you sort services by status, services with a status of “Stopped” appear before services with a status of “Running”, because the value of Status is a ServiceControllerStatus enumeration, in which “Stopped” has a value of 1 and “Running” has a value of 4.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-ChildItem | Sort-Object

    Mode                LastWriteTime     Length Name
    —-                ————-     —— —-
    -a—         9/13/2005 4:24 PM         0 0
    -a—         9/6/2005 4:19 PM         12 a.csv
    -a—         9/21/2005 3:49 PM        529 a.Ps
    -a—         8/22/2005 4:14 PM         22 a.pl
    -a—         9/27/2005 10:33 AM         24 a.txt
    -a—         9/15/2005 10:31 AM        398 a.vbs
    -a—         7/21/2005 12:39 PM     37066 a.xml
    -a—         8/28/2005 11:30 PM     5412 a.xslt
    -a—        10/25/2005 1:59 PM        125 AdamTravel.txt
    -a—         7/21/2005 9:49 AM         59 add2Num.Ps
    -a—         8/29/2005 5:42 PM     7111 Add-Content.xml
    -a—         9/21/2005 12:46 PM     8771 aliens.Ps
    -a—         8/10/2005 2:10 PM        798 array.xml
    -a—         8/4/2004 5:00 AM        110 AUTORUN.INF
    -a—         9/6/2005 4:20 PM        245 b.csv
    …

    Description
    ———–
    This command sorts the subdirectories and files in the current directory. Because no properties are specified, the files and directories are sorted in ascending alphabetical order by their default sort property, Name.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-ChildItem | Sort-Object -Property length

    Mode                LastWriteTime     Length Name
    —-                ————-     —— —-
    -a—         12/3/2006 5:35 PM         2 pref.txt
    -a—         9/6/2006 3:33 PM         15 count.txt
    -a—         7/26/2006 10:01 AM         30 filenoext
    -a—         8/18/2006 9:02 AM         52 temp.ps1
    -a—         8/18/2006 9:02 AM         52 temp.msh
    -a—         9/6/2006 3:33 PM         56 fivewords.txt
    -a—         7/26/2006 9:28 AM         80 date.csv
    -a—         7/29/2006 7:15 PM         84 test2.txt
    -a—         7/29/2006 7:15 PM         84 test.ps1

    Description
    ———–
    This command displays the files in the current directory in ascending order by file length.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Get-Process | Sort-Object -Property WS | Select-Object -last 5

    Handles NPM(K)    PM(K)     WS(K) VM(M) CPU(s)     Id ProcessName
    ——- ——    —–     —– —– ——     — ———–
     1105     25    44236     18932 197    93.81 2032 iexplore
     2526     66    37668     36836 221 393.27    868 svchost
        974     19    22844     45928 371    88.39 3952 WINWORD
     1371     22    42192     61872 323    75.75 1584 INFOPATH
     2145     58    93088     70680 619 396.69 3908 OUTLOOK

    Description
    ———–
    This command displays the five processes on the computer with the greatest memory use based on the size of their working sets.

    The command uses the Get-Process cmdlet to get a list of processes. It uses a pipeline operator (|) to send the results to the Sort-Object cmdlet, which sorts the objects in working-set order.

    Another pipeline operator sends the results to the Select-Object, which displays only the last five items in the list.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Get-History | Sort-Object -Descending

    Id CommandLine
    — ———–
    51 Get-History | sort -Descending
    50 Get-History | sort -Descending
    49 Get-History | sort -Descending
    48 Get-History | sort -Descending
    47 Get-History | sort -Descending
    46 Get-History | sort -Descending
    45 Get-History | sort -Descending
    44 cd $pshome
    43 Get-ChildItem | Sort-Object
    42 gci *.txt

    Description
    ———–
    This command sorts HistoryInfo objects using the Id property as the default key.

    ————————– EXAMPLE 5 ————————–

    C:\PS>C:\PS> Get-Service | Sort-Object -Property `
    @{Expression=”Status”;Descending=$true}, `
    @{Expression=”DisplayName”;Descending=$false}

    Status Name             DisplayName
    —— —-             ———–
    Running ALG                Application Layer Gateway Service
    Running Ati HotKey Poller Ati HotKey Poller
    Running wuauserv         Automatic Updates
    Running BITS             Background Intelligent Transfer Ser…
    Running Client for NFS     Client for NFS
    …
    Stopped clr_optimizatio… .NET Runtime Optimization Service v…
    Stopped Alerter            Alerter
    Stopped AppMgmt            Application Management
    Stopped aspnet_state     ASP.NET State Service
    Stopped ATI Smart         ATI Smart
    Stopped ClipSrv            ClipBook

    Description
    ———–
    This command displays the services on the computer in descending Status order and ascending DisplayName order.

    The command uses the Get-Service cmdlet to get the services on the computer. It uses a pipeline operator (|) to send services to the Sort-Object cmdlet.

    To sort one property in ascending order and another property in descending order, the command uses a hash table for the value of the Property parameter. The hash table uses an Expression key to specify the property name and an Ascending or Descending key to specify the sort order.

    The resulting display, which sorts the Status values in descending order, lists properties with a Status value of “Running” before those with a Status value of “Stopped”. When sorted in ascending order, “Stopped” appears before “Running”, because Status is an enumerated property in which the value of “Stopped” (1) is less than the value of “Running” (4).

    ————————– EXAMPLE 6 ————————–

    C:\PS>Get-ChildItem *.txt | Sort-Object -Property @{Expression={$_.LastWriteTime – $_.CreationTime}; Ascending=$false} | Format-Table LastWriteTime, CreationTime

    LastWriteTime                         CreationTime
    ————-                         ————
    2/21/2006 10:22:20 AM                 10/3/2005 4:19:40 PM
    2/27/2006 8:14:24 AM                    2/23/2006 10:41:08 PM
    2/24/2006 1:26:19 PM                    2/23/2006 11:23:36 PM
    1/5/2006 12:01:35 PM                    1/5/2006 11:35:30 AM
    2/24/2006 9:25:40 AM                    2/24/2006 9:22:24 AM
    2/24/2006 9:40:01 AM                    2/24/2006 9:39:41 AM
    2/21/2006 10:21:30 AM                 2/21/2006 10:21:30 AM

    Description
    ———–
    This command sorts text files in descending order by the time span between CreationTime and LastWriteTime.

    ————————– EXAMPLE 7 ————————–

    C:\PS>Get-Content servers.txt

    localhost
    test01
    server01
    server02
    localhost
    server01

    C:\PS> Get-Content servers.txt | Sort-Object -Unique
    localhost
    server01
    server02
    test01

    Description
    ———–
    These commands sort the names of servers in a text file. The second command uses the Sort-Object cmdlet with the Unique parameter to return a sorted list without duplicates.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113403
    Group-Object

New-PSSessionOption

NAME
    New-PSSessionOption

SYNOPSIS
    Creates an object that contains advanced options for a PSSession.

SYNTAX
    New-PSSessionOption [-ApplicationArguments <PSPrimitiveDictionary>] [-CancelTimeout <int>] [-Culture <CultureInfo>] [-IdleTimeout <int>] [-MaximumReceivedDataSizePerCommand <int>] [-MaximumReceivedObjectSize <int>] [-MaximumRedirection <int>] [-NoCompression] [-NoEncryption] [-NoMachineProfile] [-OpenTimeout <int>] [-OperationTimeout <int>] [-ProxyAccessType {None | IEConfig | WinHttpConfig | AutoDetect | NoProxyServer}] [-ProxyAuthentication {Default | Basic | Negotiate | NegotiateWithImplicitCredential | Credssp | Digest | Kerberos}] [-ProxyCredential <PSCredential>] [-SkipCACheck] [-SkipCNCheck] [-SkipRevocationCheck] [-UICulture <CultureInfo>] [-UseUTF16] [<CommonParameters>]

DESCRIPTION
    The New-PSSessionOption cmdlet creates an object that contains advanced options for a PSSession. You can use the object as the value of the SessionOption parameter of cmdlets that create a PSSession, such as New-PSSession, Enter-PSSession, and Invoke-Command.

    Without parameters, New-PSSessionOption generates an object that contains the default values for all of the options. Because all of the properties can be edited, you can use the resulting object as a template, and create standard option objects for your enterprise.

PARAMETERS
    -ApplicationArguments <PSPrimitiveDictionary>
        Specifies a hash table that is sent directly to the session configuration without interpretation. This hash table is available to the session configuration as a property of the PSSenderInfo class.

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

    -CancelTimeout <int>
        Determines how long Windows PowerShell waits for a cancel operation (CTRL + C) to complete before terminating it. Enter a value in milliseconds.

        The default value is 60000 (one minute). A value of 0 (zero) means no timeout; the command continues indefinitely.

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

    -Culture <CultureInfo>
        Specifies the culture to use for the PSSession. Enter a culture name in <languagecode2>-<country/regioncode2> format, such as “ja-jP”, a Variable that contains a CultureInfo object, or a command that gets a CultureInfo object, such as “Get-Culture“.

        The default value is $null, and the culture that is set in the operating system when the PSSession is created is used in the PSSession.

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

    -IdleTimeout <int>
        Determines how long the PSSession stays open if the remote computer does not receive any communication from the local computer, including the heartbeat signal. When the interval expires, the PSSession closes.

        Enter a value in milliseconds. The default value is 240000 (4 minutes). The minimum value is 60000 (1 minute).

        If both the local and remote computers specify an idle timeout value, the PSSession uses the shorter timeout value. The local computer can set an idle timeout value by using this parameter or by setting an idle timeout in the $PSSessionOption preference Variable. The remote computer can specify an idle timeout value in the WS-Management configuration (WSMAN:\localhost\shell\idletimeout).

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

    -MaximumReceivedDataSizePerCommand <int>
        Specifies the maximum number of bytes that the local computer can receive from the remote computer in a single command. Enter a value in bytes. By default, there is no data size limit.

        This option is designed to protect the resources on the client computer.

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

    -MaximumReceivedObjectSize <int>
        Specifies the maximum size of an object that the local computer can receive from the remote computer. Enter a value in bytes. By default, there is no data size limit.

        This option is designed to protect the resources on the client computer.

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

    -MaximumRedirection <int>
        Determines how many times Windows PowerShell redirects a connection to an alternate Uniform Resource Identifier (URI) before the connection fails. The default value is 5. A value of 0 (zero) prevents all redirection.

        This option is used in the PSSession only when the AllowRedirection parameter is used in the command that creates the PSSession.

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

    -NoCompression [<SwitchParameter>]
        Turns off packet compression in the PSSession. Compression uses more processor cycles, but it makes transmission faster.

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

    -NoEncryption [<SwitchParameter>]
        Turns off data encryption.

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

    -NoMachineProfile [<SwitchParameter>]
        Prevents loading the user’s Windows user profile. As a result, the PSSession might be created faster, but user-specific Registry settings, items such as Environment Variables, and Certificates are not available in the PSSession.

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

    -OpenTimeout <int>
        Determines how long the client computer waits for the session connection to be established. When the interval expires, the command to establish the connection fails. Enter a value in milliseconds.

        The default value is 180000 (3 minutes). A value of 0 (zero) means no time-out; the command continues indefinitely.

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

    -OperationTimeout <int>
        Determines the maximum time that any operation in the PSSession can run. When the interval expires, the operation fails. Enter a value in milliseconds.

        The default value is 180000 (3 minutes). A value of 0 (zero) means no time-out; the operation continues indefinitely.

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

    -ProxyAccessType <ProxyAccessType>
        Determines which mechanism is used to resolve the host name. Valid values are IEConfig, WinHttpConfig, AutoDetect, NoProxyServer and None. The default value is None.

        For information about the values of this parameter, see the description of the System.Management.Automation.Remoting.ProxyAccessType enumeration in the MSDN (Microsoft Developer Network) Library at http://go.microsoft.com/fwlink/?LinkId=144756.

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

    -ProxyAuthentication <AuthenticationMechanism>
        Specifies the authentication method that is used for proxy resolution. Valid values are Basic, Digest, and Negotiate. The default value is Negotiate.

        For information about the values of this parameter, see the description of the System.Management.Automation.Runspaces.AuthenticationMechanism enumeration in the MSDN library at http://go.microsoft.com/fwlink/?LinkID=144382.

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

    -ProxyCredential <PSCredential>
        Specifies the credentials to use for proxy authentication. Enter a Variable that contains a PSCredential object or a command that gets a PSCredential object, such as Get-Credential. If this option is not set, no credentials are specified.

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

    -SkipCACheck [<SwitchParameter>]
        Specifies that when connecting over HTTPS, the client does not validate that the server Certificate is signed by a trusted Certificate authority (CA).

        Use this option only when the remote computer is trusted by using another mechanism, such as when the remote computer is part of a network that is physically secure and isolated, or the remote computer is listed as a trusted host in a WinRM configuration.

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

    -SkipCNCheck [<SwitchParameter>]
        Specifies that the Certificate common name (CN) of the server does not need to match the hostname of the server. This option is used only in remote operations that use the HTTPS protocol.

        Use this option only for trusted computers.

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

    -SkipRevocationCheck [<SwitchParameter>]
        Does not validate the revocation status of the server Certificate.

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

    -UICulture <CultureInfo>
        Specifies the UI culture to use for the PSSession.

        Enter a culture name in <languagecode2>-<country/regioncode2> format, such as “ja-jP”, a Variable that contains a CultureInfo object, or a command that gets a CultureInfo object, such as Get-Culture.

        The default value is $null, and the UI culture that is set in the operating system when the PSSession is created is used in the PSSession.

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

    -UseUTF16 [<SwitchParameter>]
        Encode the request in UTF16 format rather than UTF8 format.

        Required?                    false
        Position?                    named
        Default value                False (UTF8 encoding)
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe input to this cmdlet.

OUTPUTS
    System.Management.Automation.Remoting.PSSessionOption

NOTES

        If the SessionOption parameter is not used in a command to create a PSSession, the session options are determined by the property values of the $PSSessionOption preference Variable, if it is set. For more information about the $PSSessionOption Variable, see about_preference_variables.

    ————————– EXAMPLE 1 ————————–

    C:\PS>New-PSSessionOption

    MaximumConnectionRedirectionCount : 5
    NoCompression                     : False
    NoMachineProfile                 : False
    ProxyAccessType                 : IEConfig
    ProxyAuthentication             : Negotiate
    ProxyCredential                 :
    SkipCACheck                     : False
    SkipCNCheck                     : False
    SkipRevocationCheck             : False
    OperationTimeout                 : 00:03:00
    NoEncryption                     : False
    UseUTF16                         : False
    Culture                         :
    UICulture                         :
    MaximumReceivedDataSizePerCommand :
    MaximumReceivedObjectSize         :
    ApplicationArguments             :
    OpenTimeout                     : 00:03:00
    CancelTimeout                     : 00:01:00
    IdleTimeout                     : 00:04:00

    Description
    ———–
    This command creates a session option object with all of the default values.

    ————————– EXAMPLE 2 ————————–

    C:\PS>$pso = New-PSSessionoption -Culture “fr-fr” -MaximumReceivedObjectSize 10MB

    C:\PS> New-PSSession -computerName Server01 -SessionOption $pso

    Description
    ———–
    This example shows how to use a session option object to configure a session.

    The first command creates a new session option object and saves it in the value of the $pso Variable.

    The second command uses the New-PSSession cmdlet to create a PSSession on the Server01 remote computer. The command uses the session option object in the value of the $pso Variable as the value of the SessionOption parameter of the command.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Enter-PSSession -computername Server01 -sessionOption (New-PSSessionoption -NoEncryption -NoCompression)

    Description
    ———–
    This command uses the Enter-PSSession cmdlet to start an interactive session with the Server01 computer. The value of the SessionOption parameter is a New-PSSessionOption command with the NoEncryption and NoCompression switch parameters.

    The New-PSSessionOption command is enclosed in parentheses to make sure that it runs before the Enter-PSSession command.

    ————————– EXAMPLE 4 ————————–

    C:\PS>$a = New-PSSessionoption

    MaximumConnectionRedirectionCount : 5
    NoCompression                     : False
    NoMachineProfile                 : False
    ProxyAccessType                 : IEConfig
    ProxyAuthentication             : Negotiate
    ProxyCredential                 :
    SkipCACheck                     : False
    SkipCNCheck                     : False
    SkipRevocationCheck             : False
    OperationTimeout                 : 00:03:00
    NoEncryption                     : False
    UseUTF16                         : False
    Culture                         :
    UICulture                         :
    MaximumReceivedDataSizePerCommand :
    MaximumReceivedObjectSize         :
    ApplicationArguments             :
    OpenTimeout                     : 00:03:00
    CancelTimeout                     : 00:01:00
    IdleTimeout                     : 00:04:00

    C:\PS> $a.UICulture = (UIGet-Culture)
    C:\PS> $a.OpenTimeout = (New-TimeSpan -minutes 4)
    C:\PS> $a.MaximumConnectionRedirectionCount = 1

    C:\PS> $a

    MaximumConnectionRedirectionCount : 1
    NoCompression                     : False
    NoMachineProfile                 : False
    ProxyAccessType                 : IEConfig
    ProxyAuthentication             : Negotiate
    ProxyCredential                 :
    SkipCACheck                     : False
    SkipCNCheck                     : False
    SkipRevocationCheck             : False
    OperationTimeout                 : 00:03:00
    NoEncryption                     : False
    UseUTF16                         : False
    Culture                         :
    UICulture                         : en-US
    MaximumReceivedDataSizePerCommand :
    MaximumReceivedObjectSize         :
    ApplicationArguments             :
    OpenTimeout                     : 00:04:00
    CancelTimeout                     : 00:01:00
    IdleTimeout                     : 00:04:00

    Description
    ———–
    This example demonstrates that you can edit the session option object. All properties have read/write values.

    Use this method to create a standard session object for your enterprise, and then create customized versions of it for particular uses.

    ————————– EXAMPLE 5 ————————–

    C:\PS>$PSSessionOption = New-PSSessionOption -OpenTimeout 120000

    Description
    ———–
    This command creates a $PSSessionOption preference Variable.

    When the $PSSessionOption preference Variable exists in the session, it establishes default values for options in the PSSessions that are created by using the New-PSSession, Enter-PSSession, and Invoke-Command cmdlets.

    To make the $PSSessionOption Variable available in all sessions, add it to your Windows PowerShell session and to your Windows PowerShell profile.

    For more information about the $PSSessionOption Variable, see about_preference_variables. For more information about profiles, see about_profiles.

    ————————– EXAMPLE 6 ————————–

    C:\PS>$skipCN = New-PSSessionoption -SkipCNCheck

    C:\PS> New-PSSession -computername 171.09.21.207 -UseSSL -credential domain01\user01 -sessionOption $skipCN

    Description
    ———–
    This example shows how to use a SessionOption object to fulfill the requirements for a remote session configuration.

    The first command uses the New-PSSessionOption cmdlet to create a session option object with the SkipCNCheck property. The command saves the resulting session object in the $skipCN Variable.

    The second command uses the New-PSSession cmdlet to create a new PSSession on a remote computer. The $skipCN check Variable is used in the value of the SessionOption parameter.

    Because the computer is identified by its IP address, the value of the ComputerName parameter does not match any of the common names in the Certificate used for Secure Sockets Layer (SSL). As a result, the SkipCNCheck option is required.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=144305
    Enter-PSSession
    New-PSSession
    Invoke-Command

Group-Object

NAME
    Group-Object

SYNOPSIS
    Groups objects that contain the same value for specified properties.

SYNTAX
    Group-Object [-AsHashTable] [-AsString] [[-Property] <Object[]>] [-CaseSensitive] [-Culture <string>] [-InputObject <psobject>] [-NoElement] [<CommonParameters>]

DESCRIPTION
    The Group-Object cmdlet displays objects in groups based on the value of a specified property. Group-Object returns a table with one row for each property value and a column that displays the number of items with that value.

    If you specify more than one property, Group-Object first groups them by the values of the first property, and then, within each property group, it groups by the value of the next property.

PARAMETERS
    -AsHashTable [<SwitchParameter>]
        Returns the group as a hash table. The keys of the hash table are the property values by which the objects are grouped. The values of the hash table are the objects that have that property value.

        By itself, the AsHashTable parameter returns each hash table in which each key is an instance of the grouped object. When used with the AsString parameter, the keys in the hash table are strings.

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

    -AsString [<SwitchParameter>]
        Converts the hash table keys to strings. By default, the hash table keys are instances of the grouped object. This parameter is valid only when used with the AsHashTable parameter.

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

    -CaseSensitive [<SwitchParameter>]
        Makes the grouping case-sensitive. Without this parameter, the property values of objects in a group might have different cases.

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

    -Culture <string>
        Specifies the culture to use when comparing strings.

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

    -InputObject <psobject>
        Specifies the objects to group. Enter a Variable that contains the objects, or type a command or expression that gets the objects.

        When you use the InputObject parameter to submit a collection of objects to Group-Object, Group-Object receives one object that represents the collection. As a result, it creates a single group with that object as its member.

        To group the objects in a collection, pipe the objects to Group-Object.

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

    -NoElement [<SwitchParameter>]
        Omits the members of a group from the results.

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

    -Property <Object[]>
        Specifies the properties for grouping. The objects are arranged into groups based on the value of the specified property.

        The value of the Property parameter can be a new calculated property. To create a calculated, property, create a hash table with an Expression key that specifies a string or script block value.

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

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe any object to Group-Object

OUTPUTS
    Microsoft.PowerShell.Commands.GroupInfo or System.Collections.Hashtable
        When you use the AsHashTable parameter, Group-Object returns a hash table. Otherwise, it returns a GroupInfo object.

NOTES

        You can also use the GroupBy parameter of the formatting cmdlets (such as Format-Table [m2] and Format-List [m2]) to group objects. Unlike Group-Object, which creates a single table with a row for each property value, the GroupBy parameters create a table for each property value with a row for each item that has the property value.

        Group-Object does not require that the objects being grouped be of the same Microsoft .NET Framework type. When grouping objects of different .NET Framework types, Group-Object uses the following rules:

        — Same Property Names and Types: If the objects have a property with the specified name, and the property values have the same .NET Framework type, the property values are grouped by using the same rules that would be used for objects of the same type.

        — Same Property Names, Different Types: If the objects have a property with the specified name, but the property values have a different .NET Framework type in different objects, Group-Object uses the .NET Framework type of the first occurrence of the property as the .NET Framework type for that property group. When an object has a property with a different type, the property value is converted to the type for that group. If the type conversion fails, the object is not included in the group.

        — Missing Properties: Objects that do not have a specified property are considered ungroupable. Ungroupable objects appear in the final GroupInfo object output in a group named AutomationNull.Value.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-ChildItem *.doc | Group-Object -Property length

    Description
    ———–
    This command gets the files in the current location that have a .doc extension and groups them by size.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-ChildItem | Sort-Object -Property extension | Group-Object -Property extension

    Description
    ———–
    This command gets the files in the current location, sorts them by file name extension, and then groups them by file name extension. Note that the files are sorted before they are grouped.

    ————————– EXAMPLE 3 ————————–

    C:\PS>1..35 | Group-Object -Property {$_ % 2},{$_ % 3}

    Description
    ———–
    This example shows how to use script blocks as the value of the Property parameter.

    This command displays the integers from 1 to 35, grouped by the remainder left when they are divided by 2 or 3.

    ————————– EXAMPLE 4 ————————–

    C:\PS>$events = Get-Eventlog -logname system -newest 1000

    C:\PS> $events | Group-Object -Property eventID

    Count Name                     Group
    —– —-                     —–
     44 Information             {System.Diagnostics.EventLogEntry,
        5 Error                     {System.Diagnostics.EventLogEntry,
        1 Warning                 {System.Diagnostics.EventLogEntry}

    Description
    ———–
    These commands display the 1,000 most recent entries in the System event log, grouped by Event ID.

    The first command uses the Get-EventLog cmdlet to retrieve the events and the assignment operator (=) to save them in the $events Variable.

    The second command uses a pipeline operator (|) to send the events in the $events Variable to the Group-Object cmdlet. The command uses the Property parameter to specify that the events should be grouped according to the value of their EventID property.

    In the output, the Count column represents the number of entries in each group, the Name column represents the EventID values that define a group, and the Group column represents the objects in each group.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-Process | Group-Object -Property priorityclass

    Count Name                Group
    —– —-                —–
     55 Normal             {System.Diagnostics.Process (AdtAgent), System.Diagnostics.Process (alg), System.Dia…
        1                     {System.Diagnostics.Process (Idle)}
        3 High                {System.Diagnostics.Process (Newproc), System.Diagnostics.Process (winlogon), System.D…
        2 BelowNormal         {System.Diagnostics.Process (winperf),

    C:\PS>Get-Process | Group-Object -Property company -NoElement
    Count Name
    —– —-
     55 Normal
        1
        3 High
        2 BelowNormal

    Description
    ———–
    This example demonstrates the effect of the NoElement parameter. These commands group the processes on the computer by priority class.

    The first command uses the Get-Process cmdlet to get the processes on the computer. It uses a pipeline operator (|) to send the results to Group-Object, which groups the objects by the value of the PriorityClass property of the process.

    The second command is identical to the first, except that it uses the NoElement parameter to eliminate the members of the group from the output. The result is a table with only the count and property value name.

    The results are shown in the following sample output.

    ————————– EXAMPLE 6 ————————–

    C:\PS>Get-Eventlog -logname system -newest 1000 | Group-Object -Property {$_.TimeWritten – $_.TimeGenerated}

    Description
    ———–
    This command demonstrates how to provide the value of the Property parameter as a script block.

    This command displays the most recent 1,000 entries from the system event log, grouped according to the time between when they were generated and when they were written to the log.

    The command uses the Get-EventLog cmdlet to get the event log entries. It uses a pipeline operator (|) to send the entries to the Group-Object cmdlet. The value of the Property parameter is specified as a script block (an expression in braces). The result of evaluating the script block is the time between when the log entry was generated and when it was written to the log. That value is used to group the 1,000 most recent events.

    ————————– EXAMPLE 7 ————————–

    C:\PS>Get-ChildItem | Group-Object extension -NoElement

    Count Name
    —– —-
     21
     82 .txt
        9 .cmd
        5 .log
     12 .xml
        5 .htm
     36 .ps1
        1 .psc1
        3 .exe
        6 .csv
        1 .psd1
        2 .bat

    Description
    ———–
    This command groups the items in the current directory by file name extension. It uses the NoElement parameter to omit the members of the group.

    The results are shown in the following sample output.

    ————————– EXAMPLE 8 ————————–

    C:\PS>”a”, “b”, “c”, “c”, “d” | Get-Unique

    a
    b
    c
    d

    C:\PS> “a”, “b”, “c”, “c”, “d” | Group-Object -NoElement | where {$_.Count -gt 1}
    Count Name
    —– —-
        2 c

    C:\PS> Get-Process | Group-Object -Property Name -NoElement | where {$_.count -gt 1}
    Count Name
    —– —-
        2 csrss
        5 svchost
        2 winlogon
        2 wmiprvse

    Description
    ———–
    This example shows how to find the unique and non-unique (repeated) property values in a collection.

    The first command gets the unique elements of an array by piping the array to the Get-Unique cmdlet.

    The second command gets the non-unique elements of an array. It pipes the array to the Group-Object cmdlet, which groups the objects by value. The resulting groups are piped to the Where-Object cmdlet, which selects objects with groups with more than one member.

    The third command shows a practical use for this technique. It uses the same method to find processes on the computer that have the same process name.

    The results are shown in the following sample output.

    ————————– EXAMPLE 9 ————————–

    C:\PS>$a = Get-Command get-*, set-* -type cmdlet | Group-Object -Property verb -AsHashTable -AsString

    C:\PS> $a

    Name    Value
    —-    —–
    Get     {Get-PSCallStack, Get-PSBreakpoint, Get-PSDrive, Get-PSSession…}
    Set     {Set-Service, Set-StrictMode, Set-PSDebug, Set-PSSessionConfiguration…}

    C:\PS> $a.get

    CommandType     Name                 Definition
    ———–     —-                 ———-
    Cmdlet         Get-PSCallStack     Get-PSCallStack [-Verbose] [-Debug] [-ErrorAction <ActionPrefer…
    Cmdlet         Get-PSBreakpoint     Get-PSBreakpoint [[-Id] <Int32[]>] [-Verbose] [-Debug] [-ErrorA…
    Cmdlet         Get-PSDrive         Get-PSDrive [[-Name] <String[]>] [-Scope <String>] [-PSProvider…
    …

    Description
    ———–
    This example uses the AsHashTable and AsString parameters to return the groups in a hash table, that is, as a collection of key-value pairs.

    In the resulting hash table, each property value is a key, and the group elements are the values. Because each key is a property of the hash table object, you can use dot notation to display the values.

    The first command gets the Get and Set cmdlets in the session, groups them by verb, returns the groups as a hash table, and saves the hash table in the $a Variable.

    The second command displays the hash table in $a. There are two key-value pairs, one for the Get cmdlets and one for the Set cmdlets.

    The third command uses dot notation to display the values of the Get key in $a. The values are CmdletInfo object. The AsString parameter does not convert the objects in the groups to strings.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113338

Compare-Object

NAME
    Compare-Object

SYNOPSIS
    Compares two sets of objects.

SYNTAX
    Compare-Object [-ReferenceObject] <PSObject[]> [-DifferenceObject] <PSObject[]> [-CaseSensitive] [-Culture <string>] [-ExcludeDifferent] [-IncludeEqual] [-PassThru] [-Property <Object[]>] [-SyncWindow <int>] [<CommonParameters>]

DESCRIPTION
    The Compare-Object cmdlet compares two sets of objects. One set of objects is the Reference set, and the other set is the Difference set.

    The result of the comparison indicates whether a property value appeared only in the object from the Reference set (indicated by the <= symbol), only in the object from the Difference set (indicated by the => symbol) or, if the IncludeEqual parameter is specified, in both objects (indicated by the == symbol).

PARAMETERS
    -CaseSensitive [<SwitchParameter>]
        Indicates that comparisons should be case-sensitive.

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

    -Culture <string>
        Specifies the culture to use for comparisons.

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

    -DifferenceObject <PSObject[]>
        Specifies the objects that are compared to the reference objects.

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

    -ExcludeDifferent [<SwitchParameter>]
        Displays only the characteristics of compared objects that are equal.

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

    -IncludeEqual [<SwitchParameter>]
        Displays characteristics of compared objects that are equal. By default, only characteristics that differ between the reference and difference objects are displayed.

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

    -PassThru [<SwitchParameter>]
        Passes the objects that differed to the pipeline. By default, this cmdlet does not generate any output.

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

    -Property <Object[]>
        Specifies the properties of the reference and difference objects to compare.

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

    -ReferenceObject <PSObject[]>
        Objects used as a reference for comparison.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -SyncWindow <int>
        Defines a search region in which an attempt is made to re-synchronize the order if there is no match. The default value is [Int32]::MaxValue.

        Required?                    false
        Position?                    named
        Default value                [Int32]::MaxValue
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe a DifferenceObject object to Compare-Object.

OUTPUTS
    None, or the objects that are different
        When you use the PassThru parameter, Compare-Object returns the objects that differed. Otherwise, this cmdlet does not generate any output.

NOTES

    ————————– EXAMPLE 1 ————————–

    C:\PS>Compare-Object -ReferenceObject $(Get-Content C:\test\testfile1.txt) -DifferenceObject $(Get-Content C:\test\testfile2.txt)

    Description
    ———–
    This command compares the contents of two text files. It displays only the lines that appear in one file or in the other file, not lines that appear in both files.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Compare-Object -ReferenceObject $(Get-Content C:\Test\testfile1.txt) -DifferenceObject $(Get-Content C:\Test\testfile2.txt) -IncludeEqual

    Description
    ———–
    This command compares each line of content in two text files. It displays all lines of content from both files, indicating whether each line appears in only Textfile1.txt or Textfile2.txt or whether each line appears in both files.

    ————————– EXAMPLE 3 ————————–

    C:\PS>$processes_before = Get-Process

    C:\PS> notepad

    C:\PS> $processes_after = Get-Process

    C:\PS> Compare-Object -ReferenceObject $processes_before -DifferenceObject $processes_after

    Description
    ———–
    These commands compare two sets of process objects.

    The first command uses the Get-Process cmdlet to get the processes on the computer. It stores them in the $processes_before Variable.

    The second command starts Notepad.

    The third command uses the Get-Process cmdlet again and stores the resulting processes in the $processes_after Variable.

    The fourth command uses the Compare-Object cmdlet to compare the two sets of process objects. It displaysthe differences between them, which include the new instance of Notepad.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113286
    Group-Object
    Measure-Object
    Sort-Object
    ForEach-Object
    New-Object
    Select-Object
    Tee-Object
    Where-Object