Category Archives: Get

Get-ExecutionPolicy

NAME
    Get-ExecutionPolicy

SYNOPSIS
    Gets the execution policies for the current session.

SYNTAX
    Get-ExecutionPolicy [[-Scope] {Process | CurrentUser | LocalMachine | UserPolicy | MachinePolicy}] [-List] [<CommonParameters>]

DESCRIPTION
    The Get-ExecutionPolicy cmdlet gets the execution policies for the current session.

    The execution policy is determined by execution policies that you set by using Set-ExecutionPolicy and the Group Policy settings for the Windows PowerShell execution policy. The default value is “Restricted.”

    Without parameters, Get-ExecutionPolicy gets the execution policy that is effective in the session. You can use the List parameter to get all execution policies that affect the session or the Scope parameter to get the execution policy for a particular scope.

    For more information, see about_execution_policies.

PARAMETERS
    -List [<SwitchParameter>]
        Gets all execution policy values for the session listed in precedence order. By default, Get-ExecutionPolicy gets only the effective execution policy.

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

    -Scope <ExecutionPolicyScope>
        Gets the execution policy in the specified scope. By default, Get-ExecutionPolicy gets the effective execution policy for the current session.

        Valid values are:

        — MachinePolicy: The execution policy set by a Group Policy for all users of the computer.
        — UserPolicy: The execution policy set by a Group Policy for the current user of the computer.
        — Process: The execution policy that is set for the current Windows PowerShell process.
        — CurrentUser: The execution policy that is set for the current user.
        — LocalMachine: The execution policy that is set for all users of the computer.

        Required?                    false
        Position?                    1
        Default value                Effective execution policy
        Accept pipeline input?     true (ByPropertyName)
        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
    Microsoft.PowerShell.ExecutionPolicy
        Get-ExecutionPolicy returns an object for each execution policy that it gets.

NOTES

        You cannot use Get-ExecutionPolicy to get particular execution policies set for a particular scope or to get the execution policy set by a Group Policy. Get-ExecutionPolicy only gets the effective execution policy that results from applying all precedence rules.

        The execution policy is part of the security strategy of Windows PowerShell. It determines whether you can load configuration files (including your Windows PowerShell profile) and run scripts, and it determines which scripts, if any, must be digitally signed before they will run.

        The effective execution policy is determined by the policies that you set by using Set-ExecutionPolicy and the “Turn on Script Execution” group policies for computers and users. The precedence order is Computer Group Policy > User Group Policy > Process (session) execution policy > User execution policy > Computer execution policy.

        For more information about Windows PowerShell execution policy, including definitions of the Windows PowerShell policies, see about_execution_policies.

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

    C:\PS>Get-ExecutionPolicy

    Restricted

    Description
    ———–
    This command gets the current execution policy for the shell.

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

    C:\PS>Set-ExecutionPolicy RemoteSigned; Get-ExecutionPolicy

    RemoteSigned

    Description
    ———–
    These commands set a new user preference for the shell execution policy and then display the effective execution policy. The commands are separated by a semicolon (;). In this example, because there is no Group Policy setting, the user preference is the effective policy for the shell.

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

    C:\PS>Get-ExecutionPolicy -List

            Scope ExecutionPolicy
            —– —————
    MachinePolicy Undefined
     UserPolicy Undefined
         Process Undefined
     CurrentUser AllSigned
     LocalMachine RemoteSigned

    C:\PS> Get-ExecutionPolicy
    AllSigned

    Description
    ———–
    These commands get all execution policies in the current session and the effective execution policy.

    The first command gets all execution policies that affect the current session. The policies are listed in precedence order.

    The second command gets only the effective execution policy, which is the one set in the CurrentUser scope.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113315
    Set-ExecutionPolicy
    Get-AuthenticodeSignature
    Set-AuthenticodeSignature
    about_execution_policies
    about_Signing

Get-FormatData

NAME
    Get-FormatData

SYNOPSIS
    Gets the formatting data in the current session.

SYNTAX
    Get-FormatData [[-TypeName] <string[]>] [<CommonParameters>]

DESCRIPTION
    The Get-FormatData cmdlet gets the formatting data in the current session.

    The formatting data in the session includes formatting data from Format.ps1xml formatting files (such as those in the $pshome directory), formatting data for modules that you import into the session, and formatting data for commands that you import into your session by using the Import-PSSession cmdlet.

    You can use this cmdlet to examine the formatting data. Then, you can use the Export-FormatData cmdlet to serialize the objects (convert them to XML) and save them in Format.ps1xml files.

    For more information about formatting files in Windows PowerShell, see about_Format.ps1xml.

PARAMETERS
    -TypeName <string[]>
        Gets only the formatting data with the specified type names. Enter the type names. Wildcards are permitted.

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

    <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.ExtendedTypeDefinition

NOTES

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

    C:\PS>Get-FormatData

    Description
    ———–
    This command gets all the formatting data in the session.

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

    C:\PS>Get-FormatData -TypeName Microsoft.Wsman*

    Description
    ———–
    This command gets the formatting data items whose names begin with “Microsoft.Wsman”.

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

    C:\PS>$f = Get-FormatData -TypeName helpinfoshort

    C:\PS> $f

    TypeName        FormatViewDefinition
    ——–        ——————–
    HelpInfoShort {help , TableControl}

    C:\PS> $f.FormatViewDefinition[0].control

    Headers                                                                    Rows
    ——-                                                                    —-
    {System.Management.Automation.TableControlColumnHeader, System.Manageme… {System.Management.Automation.TableControlRow}

    C:\PS> $f.FormatViewDefinition[0].control.headers

    Label         Alignment     Width
    —–         ———     —–
    Name         Left         33
    Category     Left         9
                 Undefined     0

    Description
    ———–
    This example shows how to get a formatting data object and examine its properties.

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

    C:\PS>$a = Get-FormatData

    C:\PS> Import-Module bitstransfer
    C:\PS> $b = Get-FormatData
    C:\PS> Compare-Object $a $b

    InputObject                                                SideIndicator
    ———–                                                ————-
    Microsoft.BackgroundIntelligentTransfer.Management.BitsJob =>

    C:\PS> Get-FormatData *bits* | Export-FormatData -filepath c:\test\bits.format.ps1xml

    C:\PS> Get-Content c:\test\bits.format.ps1xml

    <?xml version=”1.0″ encoding=”utf-8″?><Configuration><ViewDefinitions>
    <View><Name>Microsoft.BackgroundIntelligentTransfer.Management.BitsJob</Name>
    …

    Description
    ———–
    This example shows how to use Get-FormatData and Export-FormatData to export the formatting data that is added by a module.

    The first four commands use the Get-FormatData, Import-Module, and Compare-Object cmdlets to identify the format type that the BitsTransfer module adds to the session.

    The fifth command uses the Get-FormatData cmdlet to get the format type that the BitsTransfer module adds. It uses a pipeline operator (|) to send the format type object to the Export-FormatData cmdlet, which converts it back to XML and saves it in the specified format.ps1xml file.

    The final command shows an excerpt of the format.ps1xml file content.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=144303
    Export-FormatData
    Update-FormatData

Get-Event

NAME
    Get-Event

SYNOPSIS
    Gets the events in the event queue.

SYNTAX
    Get-Event [-EventIdentifier] <int> [<CommonParameters>]

    Get-Event [[-SourceIdentifier] <string>] [<CommonParameters>]

DESCRIPTION
    The Get-Event cmdlet gets events in the Windows PowerShell event queue for the current session. You can get all events or use the EventIdentifier or SourceIdentifier parameters to specify the events.

    When an event occurs, it is added to the event queue. The event queue includes events for which you have registered, events created by using the New-Event cmdlet, and the event that is raised when Windows PowerShell exits. You can use Get-Event or Wait-Event to get the events.

    This cmdlet does not get events from the Event Viewer logs. To get those events, use Get-WinEvent or Get-EventLog.

PARAMETERS
    -EventIdentifier <int>
        Gets only the events with the specified event identifier.

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

    -SourceIdentifier <string>
        Gets only events with the specified source identifier. The default is all events in the event queue. Wildcards are not permitted.

        Required?                    false
        Position?                    1
        Default value                All events
        Accept pipeline input?     true (ByPropertyName)
        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.PSEventArgs
        Get-Event returns a PSEventArgs object for each event. To see a description of this object, type “Get-Help Get-Event -full” and see the Notes section of the help topic.

NOTES

        Events, event subscriptions, and the event queue exist only in the current session. If you close the current session, the event queue is discarded and the event subscription is canceled.

        The Get-Event cmdlet returns a PSEventArgs object (System.Management.Automation.PSEventArgs) with the following properties.

        — ComputerName: The name of the computer on which the event occurred. This property value is populated only when the event is forwarded from a remote computer.

        — RunspaceId: A GUID that uniquely identifies the session in which the event occurred. This property value is populated only when the event is forwarded from a remote computer.

        — EventIdentifier: An integer (Int32) that uniquely identifies the event notification in the current session.

        — Sender: The object that generated the event. In the value of the Action parameter, the $Sender automatic Variable contains the sender object.

        — SourceEventArgs: The first parameter that derives from EventArgs, if it exists. For example, in a timer elapsed event in which the signature has the form “Object sender, Timers.ElapsedEventArgs e”, the SourceEventArgs property would contain the Timers.ElapsedEventArgs. In the value of the Action parameter, the $SourceEventArgs automatic Variable contains this value.

        — SourceArgs: All parameters of the original event signature. For a standard event signature, $args[0] represents the sender, and $args[1] represents the SourceEventArgs. In the value of the Action parameter, the $SourceArgs automatic Variable contains this value.

        — SourceIdentifier: A string that identifies the event subscription. In the value of the Action parameter, the SourceIdentifier property of the $Event automatic Variable contains this value.

        — TimeGenerated: A DateTime object that represents the time at which the event was generated. In the value of the Action parameter, the TimeGenerated property of the $Event automatic Variable contains this value.

        –MessageData: Data associated with the event subscription. Users specify this data when they register an event. In the value of the Action parameter, the MessageData property of the $Event automatic Variable contains this value.

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

    C:\PS>Get-Event

    Description
    ———–
    This command gets all events in the event queue.

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

    C:\PS>Get-Event -SourceIdentifier “PowerShell.ProcessCreated”

    Description
    ———–
    This command gets events in which the value of the SourceIdentifier property is “PowerShell.ProcessCreated”.

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

    C:\PS>$events = Get-Event

    C:\PS> $events[0] | Format-List -property *

    ComputerName     :
    RunspaceId     : c2153740-256d-46c0-a57c-b805917d1b7b
    EventIdentifier : 1
    Sender         : System.Management.ManagementEventWatcher
    SourceEventArgs : System.Management.EventArrivedEventArgs
    SourceArgs     : {System.Management.ManagementEventWatcher, System.Management.EventArrivedEventArgs}
    SourceIdentifier : ProcessStarted
    TimeGenerated    : 11/13/2008 12:09:32 PM
    MessageData     :

    C:\PS> Get-Event | where {$_.TimeGenerated -ge “11/13/2008 12:15:00 PM”}

    ComputerName     :
    RunspaceId     : c2153740-256d-46c0-a57c-b8059325d1a0
    EventIdentifier : 1
    Sender         : System.Management.ManagementEventWatcher
    SourceEventArgs : System.Management.EventArrivedEventArgs
    SourceArgs     : {System.Management.ManagementEventWatcher, System.Management.EventArrivedEventArgs}
    SourceIdentifier : ProcessStarted
    TimeGenerated    : 11/13/2008 12:15:00 PM
    MessageData     :

    Description
    ———–
    This example shows how to get events by using properties other than SourceIdentifier.

    The first command gets all events in the event queue and saves them in the $events Variable.

    The second command uses array notation to get the first (0-index) event in the array in the $events Variable. The command uses a pipeline operator (|) to send the event to the Format-List command, which displays all properties of the event in a list. This allows you to examine the properties of the event object.

    The third command shows how to use the Where-Object cmdlet to get an event
    based on the time that it was generated.

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

    C:\PS>Get-Event -eventIdentifier 2

    Description
    ———–
    This command gets the event with an event identifier of 2.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113453
    Register-ObjectEvent
    Register-EngineEvent
    Register-WmiEvent
    Unregister-Event
    New-Event
    Remove-Event
    Wait-Event

Get-EventLog

NAME
    Get-EventLog

SYNOPSIS
    Gets the events in an event log, or a list of the event logs, on the local or remote computers.

SYNTAX
    Get-EventLog [-AsString] [-ComputerName <string[]>] [-List] [<CommonParameters>]

    Get-EventLog [-LogName] <string> [[-InstanceId] <Int64[]>] [-After <DateTime>] [-AsBaseObject] [-Before <DateTime>] [-ComputerName <string[]>] [-EntryType <string[]>] [-Index <Int32[]>] [-Message <string>] [-Newest <int>] [-Source <string[]>] [-UserName <string[]>] [<CommonParameters>]

DESCRIPTION
    The Get-EventLog cmdlet gets events and event logs on the local and remote computers.

    Use the parameters of Get-EventLog to search for events by using their property values. Get-EventLog gets only the events that match all of the specified property values.

    The cmdlets that contain the EventLog noun (the EventLog cmdlets) work only on classic event logs. To get events from logs that use the Windows Event Log technology in Windows Vista and later versions of Windows, use Get-WinEvent.

PARAMETERS
    -After <DateTime>
        Gets only the events that occur after the specified date and time. Enter a DateTime object, such as the one returned by the Get-Date cmdlet.

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

    -AsBaseObject [<SwitchParameter>]
        Returns a standard System.Diagnostics.EventLogEntry object for each event. Without this parameter, Get-EventLog returns an extended PSObject object with additional EventLogName, Source, and InstanceId properties.

        To see the effect of this parameter, pipe the events to the Get-Member cmdlet and examine the TypeName value in the result.

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

    -AsString [<SwitchParameter>]
        Returns the output as strings, instead of objects.

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

    -Before <DateTime>
        Gets only the events that occur before the specified date and time. Enter a DateTime object, such as the one returned by the Get-Date cmdlet.

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

    -ComputerName <string[]>
        Specifies a remote computer. The default is the local computer.

        Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name of a remote computer. To specify the local computer, type the computer name, a dot (.), or “localhost”.

        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-EventLog even if your computer is not configured to run remote commands.

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

    -EntryType <string[]>
        Gets only events with the specified entry type. Valid values are Error, Information, FailureAudit, SuccessAudit, and Warning. The default is all events.

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

    -Index <Int32[]>
        Gets only events with the specified index values.

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

    -InstanceId <Int64[]>
        Gets only events with the specified instance IDs.

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

    -List [<SwitchParameter>]
        Gets a list of event logs on the computer.

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

    -LogName <string>
        Specifies the event log. Enter the log name (the value of the Log property; not the LogDisplayName) of one event log. Wildcard characters are not permitted. This parameter is required.

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

    -Message <string>
        Gets events that have the specified string in their messages. You can use this property to search for messages that contain certain words or phrases. Wildcards are permitted.

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

    -Newest <int>
        Specifies the maximum number of events retrieved. Get-EventLog gets the specified number of events, beginning with the newest event in the log.

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

    -Source <string[]>
        Gets events that were written to the log by the specified sources. Wildcards are permitted.

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

    -UserName <string[]>
        Gets only the events that are associated with the specified user names. Enter names or name patterns, such as User01, User*, or Domain01\User*. Wildcards are permitted.

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

    <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.Diagnostics.EventLogEntry. System.Diagnostics.EventLog. System.String
        If the LogName parameter is specified, the output is a collection of EventLogEntry objects (System.Diagnostics.EventLogEntry).

        If only the List parameter is specified, the output is a collection of EventLog objects (System.Diagnostics.EventLog).

        If both the List and AsString parameters are specified, the output is a collection of Strings (System.String).

NOTES

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

    C:\PS>Get-Eventlog -list

    Description
    ———–
    This command displays information about the event logs on the computer.

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

    C:\PS>Get-Eventlog -Newest 5 -LogName application

    Description
    ———–
    This command displays the five most recent entries in the Application event log.

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

    C:\PS>$events = Get-Eventlog -LogName system -Newest 1000

    C:\PS> $events | Group-Object -property source -noelement | Sort-Object -property count -descending

    Count Name
    —– —-
     75 Service Control Manager
     12 Print
        6 UmrdpService
        2 DnsApi
        2 DCOM
        1 Dhcp
        1 TermDD
        1 volsnap

    Description
    ———–
    This example shows how to find all of the sources that are represented in the 1000 most recent entries in the System event log.

    The first command gets the 1,000 most recent entries from the System event log and stores them in the $events Variable.

    The second command uses a pipeline operator (|) to send the events in $events to the Group-Object cmdlet, which groups the entries by the value of the Source property. The command uses a second pipeline operator to send the grouped events to the Sort-Object cmdlet, which sorts them in descending order, so the most frequently appearing source is listed first.

    Source is just property of event log entries. To see all of the properties of an event log entry, pipe the events to the Get-Member cmdlet.

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

    C:\PS>Get-Eventlog -LogName System -EntryType Error

    Description
    ———–
    This command gets only error events from the System event log.

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

    C:\PS>Get-Eventlog -LogName System -InstanceId 3221235481 -Source “DCOM”

    Description
    ———–
    This command gets events from the System log that have an InstanceID of 3221235481 and a Source value of “DCOM.”

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

    C:\PS>Get-Eventlog -LogName “Windows PowerShell” -ComputerName localhost, Server01, Server02

    Description
    ———–
    This command gets the events from the “Windows PowerShell” event log on three computers, Server01, Server02, and the local computer, known as “localhost”.

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

    C:\PS>Get-Eventlog -LogName “Windows PowerShell” -Message “*failed*”

    Description
    ———–
    This command gets all the events in the Windows PowerShell event log that have a message value that includes the word “failed”.

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

    C:\PS>$a = Get-Eventlog -log System -Newest 1

    C:\PS> $a | Format-List -property *

    EventID            : 7036
    MachineName        : Server01
    Data             : {}
    Index             : 10238
    Category         : (0)
    CategoryNumber     : 0
    EntryType         : Information
    Message            : The description for Event ID
    Source             : Service Control Manager
    ReplacementStrings : {WinHTTP Web Proxy Auto-Disco
    InstanceId         : 1073748860
    TimeGenerated     : 4/11/2008 9:56:05 PM
    TimeWritten        : 4/11/2008 9:56:05 PM
    UserName         :
    Site             :
    Container         :

    Description
    ———–
    This example shows how to display all of the property values of an event.

    The first command gets the newest event from the System event log and saves it in the $a Variable.

    The second command uses a pipeline operator (|) to send the event in $a to the Format-List command, which displays all (*) of the event properties.

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

    C:\PS>Get-Eventlog -log application -Source outlook | where {$_.eventID -eq 34}

    Description
    ———–
    This command gets events in the Application event log where the source is Outlook and the event ID is 34. Even though Get-EventLog does not have an EventID parameter, you can use the Where-Object cmdlet to select events based on the value of any event property.

    ————————– EXAMPLE 10 ————————–

    C:\PS>Get-Eventlog -log system -UserName NT* | Group-Object -property username -noelement | Format-Table Count, Name -auto

    Count Name
    —– —-
     6031 NT AUTHORITY\SYSTEM
     42 NT AUTHORITY\LOCAL SERVICE
        4 NT AUTHORITY\NETWORK SERVICE

    Description
    ———–
    This command returns the events in the system log grouped by the value of their UserName property. The Get-EventLog command uses the UserName parameter to get only events in which the user name begins with “NT*”.

    ————————– EXAMPLE 11 ————————–

    C:\PS>$May31 = Get-Date 5/31/08

    C:\PS> $July1 = Get-Date 7/01/08

    C:\PS> Get-Eventlog -log “Windows PowerShell” -EntryType Error -After $may31 -Before $july1

    Description
    ———–
    This command gets all of the errors in the Windows PowerShell event log that occurred in June 2008.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113314
    Get-WinEvent
    Clear-EventLog
    Limit-EventLog
    New-EventLog
    Remove-EventLog
    Show-EventLog
    Write-EventLog
    Get-WinEvent

Get-EventSubscriber

NAME
    Get-EventSubscriber

SYNOPSIS
    Gets the event subscribers in the current session.

SYNTAX
    Get-EventSubscriber [-SubscriptionId] <int> [[-Force]] [<CommonParameters>]

    Get-EventSubscriber [[-SourceIdentifier] <string>] [[-Force]] [<CommonParameters>]

DESCRIPTION
    The Get-EventSubscriber cmdlet gets the event subscribers in the current session.

    When you subscribe to an event by using a Register event cmdlet, an event subscriber is added to your Windows PowerShell session, and the events to which you subscribed are added to your event queue whenever they are raised. To cancel an event subscription, delete the event subscriber by using the Unregister-Event cmdlet.

PARAMETERS
    -Force [<SwitchParameter>]
        Gets all event subscribers, including subscribers for events that are hidden by using the SupportEvent parameter of Register-ObjectEvent, Register-WmiEvent, and Register-EngineEvent.

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

    -SourceIdentifier <string>
        Gets only the event subscribers with the specified SourceIdentifier property value. By default, Get-EventSubscriber gets all event subscribers in the session. Wildcards are not permitted. This parameter is case-sensitive.

        Required?                    false
        Position?                    1
        Default value                All event subscribers
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -SubscriptionId <int>
        Gets only the specified subscription identifier. By default, Get-EventSubscriber gets all event subscribers in the session.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     true (ByPropertyName)
        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.PSEventSubscriber
        Get-EventSubscriber returns an object that represents each event subscriber.

NOTES

        The New-Event cmdlet, which creates a custom event, does not generate a subscriber. Therefore, the Get-EventSubscriber cmdlet will not find a subscriber object for these events. However, if you use the Register-EngineEvent cmdlet to subscribe to a custom event (in order to forward the event or to specify an action), Get-EventSubscriber will find the subscriber that Register-EngineEvent generates.

        Events, event subscriptions, and the event queue exist only in the current session. If you close the current session, the event queue is discarded and the event subscription is canceled.

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

    C:\PS>$timer = New-Object Timers.Timer

    C:\PS> $timer | Get-Member -Type Event

    C:\PS> Register-ObjectEvent -inputObject $timer -EventName Elapsed -SourceIdentifier Timer.Elapsed

    C:\PS> Get-EventSubscriber

    C:\PS> $timer = New-Object Timers.Timer

    C:\PS> $timer | Get-Member -Type Event

     TypeName: System.Timers.Timer

    Name     MemberType Definition
    —-     ———- ———-
    Disposed Event     System.EventHandler Disposed(System.Object, System.EventArgs)
    Elapsed Event     System.Timers.ElapsedEventHandler Elapsed(System.Object, System.Timers.ElapsedEventArgs)

    C:\PS> Register-ObjectEvent -InputObject $timer -EventName Elapsed -SourceIdentifier Timer.Elapsed

    C:\PS> Get-EventSubscriber

    SubscriptionId : 4
    SourceObject     : System.Timers.Timer
    EventName        : Elapsed
    SourceIdentifier : Timer.Elapsed
    Action         :
    HandlerDelegate :
    SupportEvent     : False
    ForwardEvent     : False

    Description
    ———–
    This example uses a Get-EventSubscriber command to get the event subscriber for a timer event.

    The first command uses the New-Object cmdlet to create an instance of a timer object. It saves the new timer object in the $timer Variable.

    The second command uses the Get-Member cmdlet to display the events that are available for timer objects. The command uses the Type parameter of the Get-Member cmdlet with a value of Event.

    The third command uses the Register-ObjectEvent cmdlet to register for the Elapsed event on the timer object.

    The fourth command uses the Get-EventSubscriber cmdlet to get the event subscriber for the Elapsed event.

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

    C:\PS>$timer = New-Object Timers.Timer

    C:\PS> $timer.Interval = 500

    C:\PS> Register-ObjectEvent -inputObject $timer -eventName Elapsed -SourceIdentifier Timer.Random -Action { $random = Get-Random -Min 0 -Max 100 }

    Id Name         State     HasMoreData Location Command
    — —-         —–     ———– ——– ——-
    3 Timer.Random NotStarted False                 $random = Get-Random

    C:\PS> $timer.Enabled = $true

    C:\PS> $subscriber = Get-EventSubcriber -sourceIdentifer Timer.Random

    C:\PS> ($subscriber.action).gettype().fullname
    PSEventJob

    C:\PS> $subscriber.action | Format-List -property *

    State         : Running
    Module        : __DynamicModule_6b5cbe82-d634-41d1-ae5e-ad7fe8d57fe0
    StatusMessage :
    HasMoreData : True
    Location     :
    Command     : $random = Get-Random -Min 0 -Max 100
    JobStateInfo : Running
    Finished     : System.Threading.ManualResetEvent
    InstanceId    : 88944290-133d-4b44-8752-f901bd8012e2
    Id            : 1
    Name         : Timer.Random
    ChildJobs     : {}
    …

    C:\PS> & $subscriber.action.module {$random}
    96

    C:\PS> & $subscriber.action.module {$random}
    23

    Description
    ———–
    This example shows how to use the dynamic module in the PSEventJob object in the Action property of the event subscriber.

    The first command uses the New-Object cmdlet to create a timer object. The second command sets the interval of the timer to 500 (milliseconds).

    The third command uses the Register-ObjectEvent cmdlet to register the Elapsed event of the timer object. The command includes an action that handles the event. Whenever the timer interval elapses, an event is raised and the commands in the action run. In this case, the Get-Random cmdlet generates a random number between 0 and 100 and saves it in the $random Variable. The source identifier of the event is Timer.Random.

    When you use an Action parameter in a Register-ObjectEvent command, the command returns a PSEventJob object that represents the action.

    The fourth command enables the timer.

    The fifth command uses the Get-EventSubscriber cmdlet to get the event subscriber of the Timer.Random event. It saves the event subscriber object in the $subscriber Variable.

    The sixth command shows that the Action property of the event subscriber object contains a PSEventJob object. In fact, it contains the same PSEventJob object that the Register-ObjectEvent command returned.

    The seventh command uses the Format-List cmdlet to display all of the properties of the PSEventJob object in the Action property in a list. The result reveal that the PSEventJob object has a Module property that contains a dynamic script module that implements the action.

    The remaining commands use the call operator (&) to invoke the command in the module and display the value of the $random Variable. You can use the call operator to invoke any command in a module, including commands that are not exported. In this case, the commands show the random number that is being generated when the Elapsed event occurs.

    For more information about modules, see about_modules.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135155
    Register-ObjectEvent
    Register-EngineEvent
    Register-WmiEvent
    Unregister-Event
    Get-Event
    New-Event
    Remove-Event
    Wait-Event

Get-Culture

NAME
    Get-Culture

SYNOPSIS
    Gets the current culture set in the operating system.

SYNTAX
    Get-Culture [<CommonParameters>]

DESCRIPTION
    The Get-Culture cmdlet gets information about the current culture settings. This includes information about the current language settings on the system, such as the keyboard layout, and the display format of items such as numbers, currency, and dates.

    You can also use the Get-UICulture cmdlet, which gets the current user interface culture on the system. The user-interface (UI) culture determines which text strings are used for user interface elements, such as menus and messages.

PARAMETERS
    <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.Globalization.CultureInfo
        Get-Culture returns an object that represents the current culture.

NOTES

        You can also use the $PsCulture and $PsUICulture Variables. The $PsCulture Variable stores the name of the current culture and the $PsUICulture Variable stores the name of the current UI culture.

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

    C:\PS>Get-Culture

    Description
    ———–
    This command displays information about the regional settings on the computer.

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

    C:\PS>$c = Get-Culture

    C:\PS> $c | Format-List -property *

    Parent                         : en
    LCID                         : 1033
    KeyboardLayoutId             : 1033
    Name                         : en-US
    IetfLanguageTag                : en-US
    DisplayName                    : English (United States)
    NativeName                     : English (United States)
    EnglishName                    : English (United States)
    TwoLetterISOLanguageName     : en
    ThreeLetterISOLanguageName     : eng
    ThreeLetterWindowsLanguageName : ENU
    CompareInfo                    : CompareInfo – 1033
    TextInfo                     : TextInfo – 1033
    IsNeutralCulture             : False
    CultureTypes                 : SpecificCultures, InstalledWin32Cultures, FrameworkCultures
    NumberFormat                 : System.Globalization.NumberFormatInfo
    DateTimeFormat                 : System.Globalization.DateTimeFormatInfo
    Calendar                     : System.Globalization.GregorianCalendar
    OptionalCalendars             : {System.Globalization.GregorianCalendar, System.Globalization.GregorianCalendar}
    UseUserOverride                : True
    IsReadOnly                     : False

    C:\PS> $c.calendar

    MinSupportedDateTime : 1/1/0001 12:00:00 AM
    MaxSupportedDateTime : 12/31/9999 11:59:59 PM
    AlgorithmType        : SolarCalendar
    CalendarType         : Localized
    Eras                 : {1}
    TwoDigitYearMax     : 2029
    IsReadOnly         : False

    C:\PS> $c.datetimeformat

    AMDesignator                     : AM
    Calendar                         : System.Globalization.GregorianCalendar
    DateSeparator                    : /
    FirstDayOfWeek                 : Sunday
    CalendarWeekRule                 : FirstDay
    FullDateTimePattern             : dddd, MMMM dd, yyyy h:mm:ss tt
    LongDatePattern                 : dddd, MMMM dd, yyyy
    LongTimePattern                 : h:mm:ss tt
    MonthDayPattern                 : MMMM dd
    PMDesignator                     : PM
    RFC1123Pattern                 : ddd, dd MMM yyyy HH’:’mm’:’ss ‘GMT’
    ShortDatePattern                 : M/d/yyyy
    ShortTimePattern                 : h:mm tt
    SortableDateTimePattern         : yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss
    TimeSeparator                    : :
    UniversalSortableDateTimePattern : yyyy’-‘MM’-‘dd HH’:’mm’:’ss’Z’
    YearMonthPattern                 : MMMM, yyyy
    AbbreviatedDayNames             : {Sun, Mon, Tue, Wed…}
    ShortestDayNames                 : {Su, Mo, Tu, We…}
    DayNames                         : {Sunday, Monday, Tuesday, Wednesday…}
    AbbreviatedMonthNames            : {Jan, Feb, Mar, Apr…}
    MonthNames                     : {January, February, March, April…}
    IsReadOnly                     : False
    NativeCalendarName             : Gregorian Calendar
    AbbreviatedMonthGenitiveNames    : {Jan, Feb, Mar, Apr…}
    MonthGenitiveNames             : {January, February, March, April…}

    C:\PS> $c.datetimeformat.firstdayofweek
    Sunday

    Description
    ———–
    This example demonstrates the vast amount of data in the culture object. It shows how to display the properties and sub-properties of the object.

    The first command uses the Get-Culture cmdlet to get the current culture settings on the computer. It stores the resulting culture object in the $c Variable.

    The second command displays all of the properties of the culture object. It uses a pipeline operator (|) to send the culture object in $c to the Format-List cmdlet. It uses the Property parameter to display all (*) properties of the object. (This command can be abbreviated as “$c | fl *”.)

    The remaining commands explore the properties of the culture object by using dot notation to display the values of the object properties. You can use this notation to display the value of any property of the object.

    The third command uses dot notation to display the value of the Calendar property of the culture object.

    The fourth command uses dot notation to display the value of the DataTimeFormat property of the culture object.

    Many object properties have properties. The fifth command uses dot notation to display the value of the FirstDayOfWeek property of the DateTimeFormat property.

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

Get-Date

NAME
    Get-Date

SYNOPSIS
    Gets the current date and time.

SYNTAX
    Get-Date [-Format <string>] [[-Date] <DateTime>] [-Day <int>] [-DisplayHint {Date | Time | DateTime}] [-Hour <int>] [-Minute <int>] [-Month <int>] [-Second <int>] [-Year <int>] [<CommonParameters>]

    Get-Date [-UFormat <string>] [[-Date] <DateTime>] [-Day <int>] [-DisplayHint {Date | Time | DateTime}] [-Hour <int>] [-Minute <int>] [-Month <int>] [-Second <int>] [-Year <int>] [<CommonParameters>]

DESCRIPTION
    The Get-Date cmdlet gets a DateTime object that represents the current date or a date that you specify. It can format the date and time in several Windows and UNIX formats. You can use Get-Date to generate a date or time character string, and then send the string to other cmdlets or programs.

PARAMETERS
    -Date <DateTime>
        Specifies a date and time. By default, Get-Date gets the current system date and time.

        Type the date in a format that is standard for the system locale, such as dd-MM-yyyy (German [Germany]) or MM/dd/yyyy (English [United States]).

        Required?                    false
        Position?                    1
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -Day <int>
        Specifies the day of the month that is displayed. Enter a value from 1 to 31. This value is displayed instead of the current day.

        If you specify a value that is greater than the number of days in the month, Windows PowerShell adds the number of days to the month and displays the result. For example, “Get-Date -Month 2 -Day 31″ displays “March 3”, not “February 31”.

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

    -DisplayHint <DisplayHintType>
        Determines which elements of the date and time are displayed.
        Valid values are:

        — Date: displays only the date
        — Time: displays only the time
        — DateTime: displays the date and time

        DateTime is the default.

        This parameter does not affect the DateTime object that Get-Date retrieves.

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

    -Format <string>
        Displays the date and time in the Microsoft .NET Framework format indicated by the format specifier. Enter a format specifier. For a list of available format specifiers, see “DateTimeFormatInfo Class” in the MSDN (Microsoft Developer Network) library at http://go.microsoft.com/fwlink/?LinkId=143638.

        When you use the Format parameter, Windows PowerShell retrieves only the properties of the DateTime object that it needs to display the date in the format that you specify. As a result, some of the properties and methods of DateTime objects might not be available.

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

    -Hour <int>
        Specifies the hour that is displayed. Enter a value from 1 to 23. This value is displayed instead of the current hour.

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

    -Minute <int>
        Specifies the minute that is displayed. Enter a value from 1 to 59. This value is displayed instead of the current minute.

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

    -Month <int>
        Specifies the month that is displayed. Enter a value from 1 to 12. This value is displayed instead of the current month.

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

    -Second <int>
        Specifies the second that is displayed. Enter a value from 1 to 59. This value is displayed instead of the current second.

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

    -UFormat <string>
        Displays the date and time in UNIX format. For a list of the format specifiers, see the Notes section.

        When you use the UFormat parameter, Windows PowerShell retrieves only the properties of the DateTime object that it needs to display the date in the format that you specify. As a result, some of the properties and methods of DateTime objects might not be available.

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

    -Year <int>
        Specifies the year that is displayed. Enter a value from 1 to 9999. This value is displayed instead of the current year.

        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
    None
        You cannot pipe input to this cmdlet.

OUTPUTS
    System.DateTime or System.String
        When you use the Format or UFormat parameters, the output object is System.String.

NOTES

        By default, the date-time is displayed in long-Date and long-time formats for the system locale.

        When you pipe a date to cmdlets that expect string input, such as Add-Content, Windows PowerShell converts the DateTime object to a string before adding it to the file. The default ToString() format is short date and long time. To specify an alternate format, use the Format or UFormat parameters of Get-Date.

        Uformat Values:

        The following are the values of the UFormat parameter. The format for the command is:

        Get-Date -uformat %<value>

        For example,
        Get-Date -uformat %d

        Date-Time:
        Date and time – full
        (default) (Friday, June 16, 2006 10:31:27 AM)
        c     Date and time – abbreviated (Fri Jun 16 10:31:27 2006)

        Date:
        D    Date in mm/dd/yy format (06/14/06)
        x    Date in standard format for locale (09/12/07 for English-US)

        Year:
        C Century (20 for 2006)
        Y Year in 4-digit format (2006)
        y Year in 2-digit format (06)
        G Same as ‘Y’
        g Same as ‘y’

        Month:
        b Month name – abbreviated (Jan)
        B Month name – full (January)
        h Same as ‘b’
        m Month number (06)

        Week:
        W Week of the year (00-52)
        V Week of the year (01-53)
        U Same as ‘W’

        Day:
        a Day of the week – abbreviated name (Mon)
        A Day of the week – full name (Monday)
        u Day of the week – number (Monday = 1)
        d Day of the month – 2 digits (05)
        e Day of the month – digit preceded by a space ( 5)
        j    Day of the year – (1-366)
        w Same as ‘u’

        Time:
        p AM or PM
        r Time in 12-Hour format (09:15:36 AM)
        R Time in 24-Hour format – no seconds (17:45)
        T Time in 24 hour format (17:45:52)
        X Same as ‘T’
        Z Time zone offset from Universal Time Coordinate (UTC) (-07)

        Hour:
        H Hour in 24-Hour format (17)
        I    Hour in 12 hour format (05)
        k Same as ‘H’
        l    Same as ‘I’ (Upper-case I = Lower-case L)

        Minutes & Seconds:
        M Minutes (35)
        S Seconds (05)
        s Seconds elapsed since January 1, 1970 00:00:00 (1150451174.95705)

        Special Characters:
        n newline character (\n)
        t Tab character (\t)

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

    C:\PS>Get-Date -DisplayHint date

    Tuesday, June 13, 2006

    Description
    ———–
    This command retrieves a DateTime object, but it displays only the date. It uses the DisplayHint parameter to indicate that only the date is to be displayed.

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

    C:\PS>Get-Date -Format g

    6/13/2006 12:43 PM

    Description
    ———–
    This command retrieves the current date and time and formats it in short-Date and short-time format. It uses the .NET Framework “g” format specifier (General [short date and short time]) to specify the format.

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

    C:\PS>Get-Date -uformat “%Y / %m / %d / %A / %Z”

    2006 / 06 / 13 / Tuesday / -07

    Description
    ———–
    This command retrieves the current date and time and formats it as specified by the command. In this case, the format includes the full year (%Y), the two-digit numeric month (%m), the date (%d), the full day of the week (%A), and the offset from UTC (“Zulu”).

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

    C:\PS>(Get-Date -Year 2000 -Month 12 -Day 31).dayofyear

    366

    Description
    ———–
    This command displays the day of the year for the current date. For example, December 31 is the 365th day of 2006, but it is the 366th day of 2000.

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

    C:\PS>$a = Get-Date

    C:\PS> $a.IsDaylightSavingTime()

    True

    Description
    ———–
    These commands tell you whether the current date and time are adjusted for daylight savings time in the current locale.

    The first command creates a Variable named $a and then assigns the object retrieved by Get-Date to the $a Variable. Then, it uses the IsDaylightSavingTime method on the object in $a.

    To see the properties and methods of the DateTime object, type:
     “Get-Date | Get-Member“.

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

    C:\PS>$a = Get-Date

    C:\PS> $a.ToUniversalTime()

    Tuesday, June 13, 2006 8:09:19 PM

    Description
    ———–
    These commands convert the current date and time to UTC time.

    The first command creates a Variable named $a and then assigns the object retrieved by Get-Date to the $a Variable. Then, it uses the ToUniversalTime method on the object in $a.

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

    C:\PS>$a = Get-WmiObject win32_bios -computer server01

    $a | Format-List -property Name, @{Label=”BIOS Age”; `
    Expression={(Get-Date) – $_.ConvertToDateTime($_.ReleaseDate)}}

    Name     : Default System BIOS
    BIOS Age : 1345.17:31:07.1091047

    Description
    ———–
    Windows Management Instrumentation (WMI) uses a different date-time object than the .NET Framework date-time object that Get-Date returns. To use date-time information from WMI in a command with date-time information from Get-Date, you have to use the ConvertToDateTime method to convert WMI CIM_DATETIME objects to .NET Framework DateTime objects.

    The commands in this example display the name and age of the BIOS on a remote computer, Server01.

    The first command uses the Get-WmiObject cmdlet to get an instance of the Win32_BIOS class on Server01 and then stores it in the $a Variable.

    The second command uses the pipeline operator (|) to send the WMI object stored in $a to the Format-List cmdlet. The Property parameter of Format-List is used to specify two properties to display in the list, “Name” and “BIOS Age”. The “BIOS Age” property is specified in a hash table. The table includes the Label key, which specifies the name of the property, and the Expression key, which contains the expression that calculates the BIOS age. The expression uses the ConvertToDateTime method to convert each instance of ReleaseDate to a .NET Framework DateTime object. Then, the value is subtracted from the value of the Get-Date cmdlet, which, without parameters, gets the current date.

    The backtick character (`) is the line continuation character in Windows PowerShell.

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

    C:\PS>Get-Date

    Tuesday, June 13, 2006 12:43:42 PM

    Description
    ———–
    This command gets a DateTime object and displays the current date and time in the long date and long time formats for the system locale, as though you typed “Get-Date -Format F”.

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

    C:\PS>Get-Date

    C:\PS> Tuesday, September 26, 2006 11:25:31 AM

    c:\PS>(Get-Date).ToString()
    9/26/2006 11:25:31 AM

    C:\PS>Get-Date | Add-Content test.txt
    # Adds 9/26/2006 11:25:31 AM

    C:\PS>Get-Date -Format F | Add-Content test.txt
    # Adds Tuesday, September 26, 2006 11:25:31 AM

    Description
    ———–
    These commands demonstrate how to use Get-Date with Add-Content and other cmdlets that convert the DateTime object that Get-Date generates to a string.

    The first command shows that the default display from a “Get-Date” command is in long-Date and long-time format.

    The second command shows that the default display from the ToString() method of the DateTime object is in short-Date and short-time format.

    The third command uses a pipeline operator to send the DateTime object to the Add-Content cmdlet, which adds the content to the Test.txt file. Because Add-Content uses the ToString() method of the DateTime object, the date that is added is in short-Date and short-time format.

    The fourth command uses the Format parameter of Get-Date to specify the format. When you use the Format or UFormat parameters, Get-Date generates a string, not a DateTime object. Then, when you send the string to Add-Content, it adds the string to the Test.txt file without changing it.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113313
    Set-Date
    New-TimeSpan

Get-Counter

NAME
    Get-Counter

SYNOPSIS
    Gets performance counter data from local and remote computers.

SYNTAX
    Get-Counter [-Counter] <string[]> [-ComputerName <string[]>] [-Continuous] [-MaxSamples <Int64>] [-SampleInterval <int>] [<CommonParameters>]

    Get-Counter -ListSet <string[]> [-ComputerName <string[]>] [<CommonParameters>]

DESCRIPTION
    The Get-Counter cmdlet gets live, real-time performance counter data directly from the performance monitoring instrumentation in Windows. You can use it to get performance data from the local or remote computers at the sample interval that you specify.

    Without parameters, a “Get-Counter” command gets counter data for a set of system counters.

    You can use the parameters of Get-Counter to specify one or more computers, to list the performance counter sets and the counters that they contain, and to set the sample size and interval.

PARAMETERS
    -ComputerName <string[]>
        Gets data from the specified computers. Type the NetBIOS name, an Internet Protocol (IP) address, or the fully qualified domain names of the computers. The default value is the local computer.

        Note: Get-Counter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-Counter even if your computer is not configured for remoting in Windows PowerShell.

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

    -Continuous [<SwitchParameter>]
        Gets samples continuously until you press CTRL+C. By default, Get-Counter gets only one counter sample. You can use the SampleInterval parameter to set the interval for continuous sampling.

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

    -Counter <string[]>
        Gets data from the specified performance counters. Enter one or more counter paths. Wildcards are permitted only in the Instance value. You can also pipe counter path strings to Get-Counter.

        Each counter path has the following format:
             “[\\<ComputerName>]\<CounterSet>(<Instance>)\<CounterName>”

        For example:
                “\\Server01\Processor(2)\% User Time”.

        The <ComputerName> element is optional. If you omit it, Get-Counter uses the value of the ComputerName parameter.

        Note: To get correctly formatted counter paths, use the ListSet parameter to get a performance counter set. The Paths and PathsWithInstances properties of each performance counter set contain the individual counter paths formatted as a string. You can save the counter path strings in a Variable or pipe the string directly to another Get-Counter command. For a demonstration, see the examples.

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

    -ListSet <string[]>
        Gets the specified performance counter sets on the computers. Enter the names of the counter sets. Wildcards are permitted. You can also pipe counter set names to Get-Counter.

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

    -MaxSamples <Int64>
        Specifies the number of samples to get from each counter. The default is 1 sample. To get samples continuously (no maximum sample size), use the Continuous parameter.

        To collect a very large data set, consider running a Get-Counter command as a Windows PowerShell background job. For more information, see about_jobs and Start-Job.

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

    -SampleInterval <int>
        Specifies the time between samples in seconds. The minimum value and the default value are 1 second.

        Required?                    false
        Position?                    named
        Default value                1
        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.String[]
        You can pipe counter paths and counter set (ListSet) names to Get-Counter.

OUTPUTS
    Microsoft.PowerShell.Commands.GetCounter.CounterSet, Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet, Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSample
        The ListSet parameter gets Microsoft.PowerShell.Commands.GetCounter.CounterSet objects. The Counter parameter gets Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet objects. Each counter value is a Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSample object.

NOTES

        Performance counters are often protected by access control lists (ACLs). To get all available performance counters, open Windows PowerShell with the “Run as administrator” option.

        By default, Get-Counter gets one sample during a one-second sample interval. To change this behavior, use the MaxSamples and Continuous parameters.

        The MaxSamples and SampleInterval values that you set apply to all the counters on all the computers in the command. To set different values for different counters, enter separate Get-Counter commands for each counter.

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

    C:\PS># Get-Counter

    Description
    ———–
    This command gets all of the counter sets on the local computer.

    C:\PS> Get-Counter -ListSet *

    Because many of the counter sets are protected by access control lists (ACLs), to see all counter sets, open Windows PowerShell with the “Run as administrator” option before using the Get-Counter command.

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

    C:\PS># Get-Counter

    Description
    ———–
    This command gets the current “% Processor Time” combined values for all processors on the local computer. It collects data every two seconds until it has three values.

    C:\PS> Get-Counter -Counter “\Processor(_Total)\% Processor Time” -SampleInterval 2 -MaxSamples 3

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

    C:\PS># Get-Counter

    Description
    ———–
    This command gets an alphabetically sorted list of the names of all of the counter sets on the local computer.

    C:\PS> Get-Counter -listset * | Sort-Object countersetname | Format-Table countersetname

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

    C:\PS># Get-Counter

    Description
    ———–
    These commands use the Path property of a counter set to find the correctly formatted path names for the performance counters. You can use a command like this one to get the correct counter path names.

    The first command gets the path names of the performance counters in the Memory counter set on the local computer.

    C:\PS> (Get-Counter -listset memory).paths

    \Memory\Page Faults/sec
    \Memory\Available Bytes
    \Memory\Committed Bytes
    \Memory\Commit Limit
    \Memory\Write Copies/sec
    \Memory\Transition Faults/sec
    \Memory\Cache Faults/sec
    \Memory\Demand Zero Faults/sec
    \Memory\Pages/sec
    \Memory\Pages Input/sec
    …

    The second command gets the path names that include “cache”.

    C:\PS> (Get-Counter -listset memory).paths | where {$_ -like “*cache*”}

    \Memory\Cache Faults/sec
    \Memory\Cache Bytes
    \Memory\Cache Bytes Peak
    \Memory\System Cache Resident Bytes
    \Memory\Standby Cache Reserve Bytes
    \Memory\Standby Cache Normal Priority Bytes
    \Memory\Standby Cache Core Bytes

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

    C:\PS># Get-Counter

    Description
    ———–
    These commands get the Disk Reads/sec counter data from the Server01 and Server02 computers.

    The first command saves the Disk Reads/sec counter path in the $diskreads Variable.

    C:\PS> $diskreads = “\LogicalDisk(C:)\Disk Reads/sec”

    The second command uses a pipeline operator (|) to send the counter path in the $diskreads Variable to the Get-Counter cmdlet. The command uses the MaxSamples parameter to limit the output to 10 samples.

    C:\PS> $diskreads | Get-Counter -computer Server01, Server02 -MaxSamples 10

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

    C:\PS># Get-Counter

    Description
    ———–
    This command gets the correctly formatted path names for the PhysicalDisk performance counters, including the instance names.

    C:\PS> (Get-Counter -list physicaldisk).pathswithinstances

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

    C:\PS># Get-Counter

    Description
    ———–
    These commands get the value of the “% DPC Time” performance counter on 50 randomly select computers in the enterprise.

    The first command uses the Get-Content cmdlet to get the list of enterprise servers from the Servers.txt file. It uses the Get-Random cmdlet to select 50 server names randomly from the Servers.txt file contents. The results are saved in the $servers Variable.

    C:\PS> $servers = Get-Random (Get-Content servers.txt) -count 50

    The second command saves the counter path to the “% DPC Time” cmdlet in the $Counter Variable. The counter path includes a wildcard character in the instance name to get the data on all of the processors on each of the computers.

    C:\PS> $counter = “\Processor(*)\% DPC Time”

    The third command uses the Get-Counter cmdlet to get the counter values. It uses the Counter parameter to specify the counters and the ComputerName parameter to specify the computers saved in the $servers Variable.

    C:\PS> Get-Counter -Counter $counter -ComputerName $servers

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

    C:\PS># Get-Counter

    Description
    ———–
    These commands get a single value for all of the performance counters in the memory counter set on the local computer.

    The first command gets the counter paths and saves them in the $memCounters Variable.

    C:\PS> $memCounters = (Get-Counter -list memory).paths

    The second command uses the Get-Counter cmdlet to get the counter data for each counter. It uses the Counter parameter to specify the counters in $memCounters.

    C:\PS> Get-Counter -Counter $memCounters

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

    C:\PS># Get-Counter

    Description
    ———–
    This example shows the property values in the PerformanceCounterSample object that represents each data sample.

    The first command saves a counter path in the $counter Variable.

    C:\PS> $counter = “\\SERVER01\Process(Idle)\% Processor Time”

    The second command uses the Get-Counter cmdlet to get one sample of the counter values. It saves the results in the $data Variable.

    C:\PS> $data = Get-Counter $counter

    The third command uses the Format-List cmdlet to display all the properties of the CounterSamples property of the sample set object as a list.

    C:\PS> $data.countersamples | Format-List -property *

    Path             : \\SERVER01\process(idle)\% processor time
    InstanceName     : idle
    CookedValue     : 198.467899571389
    RawValue         : 14329160321003
    SecondValue     : 128606459528326201
    MultipleCount    : 1
    CounterType     : Timer100Ns
    Timestamp        : 7/15/2008 6:39:12 PM
    Timestamp100NSec : 128606207528320000
    Status         : 0
    DefaultScale     : 0
    TimeBase         : 10000000

    You can use the properties of the CounterSamples object to examine, select, sort, and group the data.

    ————————– EXAMPLE 10 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    The command runs a Get-Counter command as background job. For more information, see Start-Job.

    C:\PS> $counters = “\LogicalDisk(_Total)\% Free Space”

    C:\PS> Start-Job -scriptblock {Get-Counter -Counter $counters -MaxSamples 1000)

    ————————– EXAMPLE 11 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This command uses the Get-Counter and Get-Random cmdlets to find the percentage of free disk space on 50 computers selected randomly from the Servers.txt file.

    C:\PS> Get-Counter -ComputerName (Get-Random servers.txt -count 50) -Counter “\LogicalDisk(*)\% Free Space”

    ————————– EXAMPLE 12 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This example shows how to associate counter data with the computer on which it originated, and how to manipulate the data.

    The first command uses the Get-Counter cmdlet to get the “LogicalDisk\% Free Space” counter value from two remote computers, S1 and S2. It saves the result in the $a Variable.

    $a = Get-Counter “\LogicalDisk(_Total)\% Free Space” -comp s1, s2

    The second command displays the results in the $a Variable. All of the data is stored in the object, but it is not easy to see it in this form.

    C:\PS> $a

    Counter Paths: \\s1\\logicaldisk(c:)\% free space, \\s1\\logicaldisk(d:)\% free space, \\s1\\logicaldisk(_total)\% free space, \\s2\\logicaldisk(c:)\% free space, \\s2\\logicaldisk(_total)\% free space

    Timestamp     : 7/15/2008 5:09:08 PM
    Cooked Values : “0.327058823529412”, “17.8952248493278”, “12.9994033060778”, “75.0754805595626”, “75.0754805595626”

    The third command displays in a table the value of the CounterSamples property of the PerformanceCounterSampleSet object that Get-Counter returns. (To see all of the properties and methods of the object, pipe it to the Get-Member cmdlet.)

    C:\PS> $a.countersamples | Format-Table -auto

    Path                                     InstanceName     CookedValue
    —-                                     ————     ———–
    \\s1\\logicaldisk(c:)\% free space     c:         0.327058823529412
    \\s1\\logicaldisk(d:)\% free space     d:            17.8952248493278
    \\s1\\logicaldisk(_total)\% free space _total        12.9994033060778
    \\s2\\logicaldisk(c:)\% free space     c:            75.0754805595626
    \\s2\\logicaldisk(_total)\% free space _total        75.0754805595626

    The CounterSamples property contains a PerformanceCounterSample object with its own properties and methods. The fourth command uses array notation to get the first counter sample and a pipeline operator to send the counter sample object to the Format-List cmdlet, which displays all of its properties and methods in a list. This display shows the richness of the data in each counter sample object.

    The fourth command shows how to select data from the counter samples. It uses the Where-Object cmdlet to get only the counter samples with a CookedValue of less than 15.

    C:\PS> $a.countersamples | where {$_.cookedvalue -lt 15}

    Path                                     InstanceName     CookedValue
    —-                                     ————     ———–
    \\s1\\logicaldisk(c:)\% free space     c:         0.327058823529412
    \\s1\\logicaldisk(_total)\% free space _total        12.9994033060778

    ————————– EXAMPLE 13 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This example shows how to sort the performance counter data that you retrieve. The example finds the processes on the computer that are using the most processor time during the sampling.

    The first command gets the “Process\% Processor Time” counter for all the processes on the computer. The command saves the results in the $p Variable.

    C:\PS> $p = Get-Counter ‘\Process(*)\% Processor Time’

    The second command gets the CounterSamples property of the sample set object in $p and it sorts the samples in descending order based on the cooked value of the sample. The command uses the Format-Table cmdlet and its AutoFormat parameter to position the columns in the table.

    C:\PS> $p.CounterSamples | Sort-Object -property CookedValue -Descending | Format-Table -auto

    Path                                             InstanceName     CookedValue
    —-                                             ————     ———–
    \\server01\process(_total)\% processor time        _total        200.00641042078
    \\server01\process(idle)\% processor time         idle         200.00641042078
    \\server01\process(explorer#1)\% processor time    explorer                    0
    \\server01\process(dwm#1)\% processor time         dwm                         0
    \\server01\process(taskeng#1)\% processor time     taskeng                     0
    \\server01\process(taskhost#1)\% processor time    taskhost                    0
    \\server01\process(winlogon)\% processor time     winlogon                    0
    \\server01\process(csrss)\% processor time         csrss                     0

    ————————– EXAMPLE 14 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    These commands find the processes on the computer with the largest working sets. They list the processes in descending order based on their working set size.

    The first command gets one sample of the “Process\Working Set – Private” counter for each process. The command saves the counter data in the $ws Variable.

    C:\PS> $ws = Get-Counter “\Process(*)\Working Set – Private”

    The second command uses a pipeline operator (|) to send the data in the CounterSamples property of the $ws Variable to the Sort-Object cmdlet, where the process data is sorted in descending order by the value of the CookedValue property. Another pipeline sends the sorted data to the Format-Table cmdlet, where the data is formatted as a table with InstanceName and CookedValue columns.

    C:\PS> $ws.countersamples | Sort-Object -property cookedvalue -descending | Format-Table -property InstanceName, CookedValue -auto

    InstanceName CookedValue
    ———— ———–
    _total         162983936
    svchost         40370176
    powershell     15110144
    explorer         14135296
    svchost         10928128
    svchost         9027584
    …

    ————————– EXAMPLE 15 ————————–

    C:\PS># Get-Counter

    Description
    ———–
    This command gets a series of samples of the Processor\% Processor Time counter at the default one second interval. To stop the command, press CTRL + C.

    C:\PS> Get-Counter -Counter “\processor(_total)\% processor time” -Continuous

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=138335
    Import-Counter
    Export-Counter

Get-Credential

NAME
    Get-Credential

SYNOPSIS
    Gets a credential object based on a user name and password.

SYNTAX
    Get-Credential [-Credential] <PSCredential> [<CommonParameters>]

DESCRIPTION
    The Get-Credential cmdlet creates a credential object for a specified user name and password. You can use the credential object in security operations.

    The cmdlet prompts the user for a password or user name and password. Users are prompted through a dialog box or at the command line, depending on the system Registry setting.

PARAMETERS
    -Credential <PSCredential>
        Specifies a user name for the credential, such as “User01” or “Domain01\User01”. The parameter name (“Credential”) is optional.

        When you submit the command, you will be prompted for a password.

        If you enter a user name without a domain, Get-Credential inserts a backslash before the name.

        If you omit this parameter, you will be prompted for a user name and a password.

        Required?                    true
        Position?                    1
        Default value                None
        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.PSCredential
        Get-Credential returns a credential object.

NOTES

        You can use the PSCredential object that Get-Credential creates in cmdlets that request user authentication, such as those with a Credential parameter.

        The Credential parameter is not supported by the providers that are installed with Windows PowerShell. However, you can use the Credential parameter with Get-WmiObject, because it calls the Microsoft .NET Framework directly.

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

    C:\PS>$c = Get-Credential

    Description
    ———–
    This command gets a credential object and saves it in the $c Variable.

    When you enter the command, a dialog box appears requesting a user name and password. When you enter the requested information, the cmdlet creates a PSCredential object representing the credentials of the user and saves it in the $c Variable.

    You can use the object as input to cmdlets that request user authentication, such as those with a Credential parameter. However, the providers that are installed with Windows PowerShell do not support the Credential parameter.

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

    C:\PS>$c = Get-Credential

    C:\PS>Get-WmiObject Win32_DiskDrive -ComputerName Server01 -Credential $c

    Description
    ———–
    These commands use a credential object from Get-Credential to authenticate a user on a remote computer so they can use Windows Management Instrumentation (WMI) to manage the computer.

    The first command gets a credential object and saves it in the $c Variable. The second command uses the credential object in a Get-WmiObject command. This command gets information about the disk drives on the Server01 computer.

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

    C:\PS>C:\PS>Get-WmiObject Win32_BIOS -ComputerName Server01 ‘
    -Credential (Get-Credential Domain01\User01)

    Description
    ———–
    This command shows how to include a Get-Credential command in a Get-WmiObject command.

    This command uses the Get-WmiObject cmdlet to get information about the BIOS on the Server01 computer. It uses the Credential parameter to authenticate the user, Domain01\User01, and a Get-Credential command as the value of the Credential parameter.

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

    C:\PS>$c = Get-Credential -Credential User01

    C:\PS>$c.Username

    \User01

    Description
    ———–
    This example creates a credential that includes a user name without a domain name. It demonstrates that Get-Credential inserts a backslash before the user name.

    The first command gets a credential with the user name User01 and stores it in the $c Variable.

    The second command displays the value of the Username property of the resulting credential object.

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

    C:\PS>$credential = $host.ui.PromptForCredential(“Need credentials”, “Please enter your user name and password.”, “”, “NetBiosUserName”)

    Description
    ———–
    This command uses the PromptForCredential method to prompt the user for their user name and password. The command saves the resulting credentials in the $credential Variable.

    PromptForCredential is an alternative to using Get-Credential. When you use PromptForCredential, you can specify the caption, messages, and user name that appear in the message box.

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

    C:\PS>Set-ItemProperty ‘HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds’ ConsolePrompting $true

    Description
    ———–
    When requiring a user name and password, as a default, a dialog box appears to prompt the user. To be prompted at the command line, modify the Registry by running this command in Windows PowerShell Run as administrator.

    Use the same command with “ConsolePrompting $false” to be prompted with a dialog box.

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

Get-Content

NAME
    Get-Content

SYNOPSIS
    Gets the content of the item at the specified location.

SYNTAX
    Get-Content [-LiteralPath] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-ReadCount <Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>]

    Get-Content [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-ReadCount <Int64>] [-TotalCount <Int64>] [-UseTransaction] [<CommonParameters>]

DESCRIPTION
    The Get-Content cmdlet gets the content of the item at the location specified by the path, such as the text in a file. It reads the content one line at a time and returns an object for each line.

PARAMETERS
    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. The default is the current user.

        Type a user name, such as “User01” or “Domain01\User01”, or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

        This parameter is not supported by any providers that are installed with Windows PowerShell.

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

    -Exclude <string[]>
        Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

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

    -Filter <string>
        Specifies a filter in the provider’s format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.

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

    -Force [<SwitchParameter>]
        Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to change file permissions.

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

    -Include <string[]>
        Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as “*.txt”. Wildcards are permitted.

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

    -LiteralPath <string[]>
        Specifies the path to an item. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

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

    -Path <string[]>
        Specifies the path to an item. Get-Content retrieves the content of the item. Wildcards are permitted. The parameter name (“Path” or “FilePath”) is optional.

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

    -ReadCount <Int64>
        Specifies how many lines of content are sent through the pipeline at a time. The default value is 1. A value of 0 (zero) sends all of the content at one time.

        This parameter does not change the content displayed, but it does affect the time it takes to display the content. As the value of ReadCount increases, the time it takes to return the first line increases, but the total time for the operation decreases. This can make a perceptible difference in very large items.

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

    -TotalCount <Int64>
        Specifies how many lines of content are retrieved. The default is -1 (all lines).

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

    -UseTransaction [<SwitchParameter>]
        Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_transactions.

        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
    None
        You cannot pipe input to Get-Content.

OUTPUTS
    Object
        Get-Content returns objects that represent the content that it gets. The object type depends on the content type.

NOTES

        You can also refer to Get-Content by its built-in Aliases, “cat”, “type” and “gc”. For more information, see about_aliases.

        The Get-Content cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type “Get-PSProvider“. For more information, see about_providers.

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

    C:\PS>Get-Content -Path C:\Chapters\chapter1.txt

    Description
    ———–
    This command displays the content of the Chapter1.txt file on the console. It uses the Path parameter to specify the name of the item. Get-Content actually passes the content down the pipeline, but because there are no other pipeline elements, the content is formatted and displayed on the console.

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

    C:\PS>Get-Content c:\Logs\Log060912.txt -TotalCount 50 | Set-Content sample.txt

    Description
    ———–
    This command gets the first 50 lines of the Log060912.txt file and stores them in the sample.txt file. The command uses the Get-Content cmdlet to get the text in the file. (The name of Path parameter, which is optional, is omitted.) The TotalCount parameter limits the retrieval to the first 50 lines. The pipeline operator (|) sends the result to Set-Content, which places it in the sample.txt file.

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

    C:\PS>(Get-Content cmdlets.txt -TotalCount 5)[-1]

    Description
    ———–
    This command gets the fifth line of the Cmdlets.txt text file. It uses the TotalCount parameter to get the first five lines and then uses array notation to get the last line (indicated by “-1”) of the resulting set.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113310
    about_providers
    Add-Content
    Set-Content
    Clear-Content