Tag Archives: ErrorVariable

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

Get-ComputerRestorePoint

NAME
    Get-ComputerRestorePoint

SYNOPSIS
    Gets the restore points on the local computer.

SYNTAX
    Get-ComputerRestorePoint [[-RestorePoint] <Int32[]>] [<CommonParameters>]

    Get-ComputerRestorePoint -LastStatus [<CommonParameters>]

DESCRIPTION
    The Get-ComputerRestorePoint cmdlet gets the restore points on the local computer. This cmdlet can also display the status of the most recent attempt to restore the computer.

    You can use the information returned by Get-ComputerRestorePoint to select a restore point, and you can use the sequence number to identify a restore point for the Restore-Computer cmdlet.

PARAMETERS
    -LastStatus [<SwitchParameter>]
        Gets the status of the most recent system restore operation.

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

    -RestorePoint <Int32[]>
        Gets the restore points with the specified sequence numbers. Enter the sequence numbers of one or more restore points. By default, Get-ComputerRestorePoint gets all restore points on the local computer.

        Required?                    false
        Position?                    1
        Default value                All restore points
        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 objects to this cmdlet.

OUTPUTS
    System.Management.ManagementObject#root\default\SystemRestore or String.
        Get-ComputerRestore returns a SystemRestore object, which is an instance of the WMI SystemRestore class. When you use the LastStatus parameter, this cmdlet returns a string.

NOTES

        To run a Get-ComputerRestorePoint command on Windows Vista and later versions of Windows, open Windows PowerShell with the “Run as administrator” option.

        This cmdlet uses the Windows Management Instrumentation (WMI) SystemRestore class.

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

    C:\PS>Get-ComputerRestorePoint

    Description
    ———–
    This command gets all of the restore points on the local computer.

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

    C:\PS>Get-ComputerRestorePoint -RestorePoint 232, 240, 245

    Description
    ———–
    This command gets the restore points with sequence numbers 232, 240, and 245.

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

    C:\PS>Get-ComputerRestorePoint -laststatus

    The last restore failed.

    Description
    ———–
    This command displays the status of the most recent system restore operation on the local computer.

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

    C:\PS>Get-ComputerRestorePoint | Format-Table SequenceNumber, @{Label=”Date”; Expression={$_.ConvertToDateTime($_.CreationTime)}}, Description -auto

    SequenceNumber Date                 Description
    ————– —-                 ———–
             253 8/5/2008 3:19:20 PM Windows Update
             254 8/6/2008 1:53:24 AM Windows Update
             255 8/7/2008 12:00:04 AM Scheduled Checkpoint
    …

    Description
    ———–
    This command displays the restore points in a table for easy reading.

    The Format-Table command includes a calculated property that uses the ConvertToDateTime method to convert the value of the CreationTime property from WMI format to a DateTime object.

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

    C:\PS>((Get-ComputerRestorePoint)[-1]).sequencenumber

    Description
    ———–
    This command gets the sequence number of the most recently created restore point on the computer.

    The command uses the -1 index to get the last item in the array that Get-ComputerRestorePoint returns.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135215
    Enable-ComputerRestore
    Disable-ComputerRestore
    Restore-Computer
    Restart-Computer

Get-Command

NAME
    Get-Command

SYNOPSIS
    Gets basic information about cmdlets and other elements of Windows PowerShell commands.

SYNTAX
    Get-Command [[-Name] <string[]>] [-CommandType {Alias | Function | Filter | Cmdlet | ExternalScript | Application | Script | All}] [[-ArgumentList] <Object[]>] [-Module <string[]>] [-Syntax] [-TotalCount <int>] [<CommonParameters>]

    Get-Command [-Noun <string[]>] [-Verb <string[]>] [[-ArgumentList] <Object[]>] [-Module <string[]>] [-Syntax] [-TotalCount <int>] [<CommonParameters>]

DESCRIPTION
    The Get-Command cmdlet gets basic information about cmdlets and other elements of Windows PowerShell commands in the session, such as Aliases, Functions, filters, scripts, and applications.

    Get-Command gets its data directly from the code of a cmdlet, Function, script, or Alias, unlike Get-Help, which gets its information from help topic files.

    Without parameters, “Get-Command” gets all of the cmdlets and Functions in the current session. “Get-Command *” gets all Windows PowerShell elements and all of the non-Windows-PowerShell files in the Path Environment Variable ($env:path). It groups the files in the “Application” command type.

    You can use the Module parameter of Get-Command to find the commands that were added to the session by adding a Windows PowerShell snap-in or importing a module.

PARAMETERS
    -ArgumentList <Object[]>
        Gets information about a cmdlet or Function when it is used with the specified parameters (“arguments”), such as a path. The Alias for ArgumentList is Args.

        To detect parameters that are added to a cmdlet when it is used with a particular provider, set the value of ArgumentList to a path in the provider drive, such as “HKML\Software” or “cert:\my”.

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

    -CommandType <CommandTypes>
        Gets only the specified types of commands. Use “CommandType” or its Alias, “Type”. By default, Get-Command gets cmdlets and Functions.

        Valid values are:
        — Alias: All Windows PowerShell Aliases in the current session.

        — All: All command types. It is the equivalent of “Get-Command *”.

        — Application: All non-Windows-PowerShell files in paths listed in the Path Environment Variable ($env:path), including .txt, .exe, and .dll files.

        — Cmdlet: The cmdlets in the current session. “Cmdlet” is the default.

        — ExternalScript: All .ps1 files in the paths listed in the Path Environment Variable ($env:path).

        — Filter and Function: All Windows PowerShell Functions.

        — Script: Script blocks in the current session.

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

    -Module <string[]>
        Gets the commands that came from the specified modules or snap-ins. Enter the names of modules or snap-ins, or enter snap-in or module objects.

        You can refer to this parameter by its name, Module, or by its Alias, PSSnapin. The parameter name that you choose has no effect on the command or its output.

        This parameter takes string values, but you can also supply a PSModuleInfo or PSSnapinInfo object, such as the objects that Get-Module, Get-PSSnapin, and Import-PSSession return.

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

    -Name <string[]>
        Gets information only about the cmdlets or command elements with the specified name. <String> represents all or part of the name of the cmdlet or command element. Wildcards are permitted.

        To list commands with the same name in execution order, type the command name without wildcard characters. For more information, see the Notes section.

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

    -Noun <string[]>
        Gets cmdlets and Functions with names that include the specified noun. <String> represents one or more nouns or noun patterns, such as “process” or “*item*”. Wildcards are permitted.

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

    -Syntax [<SwitchParameter>]
        Gets only specified data about the command element.
                 * For Aliases, retrieves the standard name.
                 * For cmdlets, retrieves the syntax.
                 * For Functions and filters, retrieves the Function definition.
                 * For scripts and applications (files), retrieves the path and filename.

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

    -TotalCount <int>
        Gets only the specified number of command elements. You can use this parameter to limit the output of a command.

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

    -Verb <string[]>
        Gets information about cmdlets and Functions with names that include the specified verb. <String> represents one or more verbs or verb patterns, such as “remove” or *et”. Wildcards are permitted.

        Required?                    false
        Position?                    named
        Default value
        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
    System.String
        You can pipe a “Name”, “Command”, and “Verb” noun-property specified, or a string object to Get-Command.

OUTPUTS
    Object
        The type of object returned depends on the type of command element retrieved. For example, Get-Command on a cmdlet retrieves a CmdletInfo object, while Get-Command on a DLL retrieves an ApplicationInfo object.

NOTES

        Without parameters, “Get-Command” gets information about the Windows PowerShell cmdlets and Functions. Use the parameters to qualify the elements retrieved.

        Unlike Get-Help, which displays the contents of XML-based help topic files, Get-Command gets its cmdlet information directly from the cmdlet code in the system.

        Get-Command returns the commands in alphabetical order. When the session contains more than one command with the same name, Get-Command returns the commands in execution order. The first command that is listed is the command that runs when you type the command name without qualification. For more information, see about_command_precedence.

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

    C:\PS>Get-Command

    Description
    ———–
    This command gets information about all of the Windows PowerShell cmdlets and Functions.

    The default display lists the command type (“Cmdlet” or “Function” or “Filter”), the name of the cmdlet or Function, and the syntax or Function definition.

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

    C:\PS>Get-Command -Verb set | Format-List

    Description
    ———–
    This command gets information about all of the cmdlets and Functions with the verb “set”, and it displays some of that information in a list.

    The list format includes fields that are omitted from the table display, including the complete syntax. To display all fields (all properties of the object), type “Get-Command -Verb set | Format-List *”.

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

    C:\PS>Get-Command -type cmdlet | Sort-Object noun | Format-Table -group noun

    Description
    ———–
    This command retrieves all of the cmdlets, sorts them alphabetically by the noun in the cmdlet name, and then displays them in noun-based
    groups. This display can help you find the cmdlets for a task.

    By default, Get-Command displays items in the order in which the system discovers them, which is also the order in which they are selected to run when a run command is ambiguous.

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

    C:\PS>Get-Command -Module Microsoft.PowerShell.Security, TestModule

    Description
    ———–
    This command gets the commands in the Microsoft.PowerShell.Security snap-in and the Test-Module module.

    The Module parameter gets commands that were added by importing modules or adding Windows PowerShell snap-ins.

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

    C:\PS>Get-Command Get-ChildItem -args cert: -Syntax

    Description
    ———–
    This command retrieves information about the Get-ChildItem cmdlet when Get-ChildItem is used with the Windows PowerShell Certificate provider.

    When you compare the syntax displayed in the output with the syntax that is displayed when you omit the Args (ArgumentList) parameter, you’ll see that the Certificate provider dynamically adds a parameter, CodeSigningCert, to the Get-ChildItem cmdlet.

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

    C:\PS>(Get-Command Get-ChildItem -ArgumentList cert:).parametersets[0].parameters | Where-Object { $_.IsDynamic }

    Description
    ———–
    This command retrieves only parameters that are added to the Get-ChildItem cmdlet dynamically when it is used with the Windows PowerShell Certificate provider. This is an alternative to the method used in the previous example.

    In this command, the “Get-Command Get-ChildItem -ArgumentList cert:” is processed first. It requests information from Get-Command about the Get-ChildItem cmdlet when it is used with the Certificate provider. The “.parametersets[0]” selects the first parameter set (set 0) of “Get-ChildItem -ArgumentList cert:” and “.parameters” selects the parameters in that parameter set. The resulting parameters are piped to the Where-Object cmdlet to test each parameter (“$_.”) by using the IsDynamic property. To find the properties of the objects in a command, use Get-Member.

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

    C:\PS>Get-Command *

    Description
    ———–
    This command gets information about the Windows PowerShell cmdlets, Functions, filters, scripts, and Aliases in the current console.

    It also gets information about all of the files in the paths of the Path Environment Variable ($env:path). It returns an ApplicationInfo object (System.Management.Automation.ApplicationInfo) for each file, not a FileInfo object (System.IO.FileInfo).

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

    C:\PS>Get-Command | Where-Object {$_.definition -like “*first*”}

    CommandType     Name                        Definition
    ———–     —-                        ———
    Cmdlet         Select-Object             Select-Object [[-Property]

    Description
    ———–
    This command finds a cmdlet or Function based on the name of one of its parameters. You can use this command to identify a cmdlet or Function when all that you can recall is the name of one of its parameters.

    In this case, you recall that one of the cmdlets or Functions has a First parameter that gets the first “n” objects in a list, but you cannot remember which cmdlet it is.

    This command uses the Get-Command cmdlet to get a CmdletInfo object representing each of the cmdlets and Functions in the session. The CmdletInfo object has a Definition property that contains the syntax of the cmdlet or Function, which includes its parameters.

    The command uses a pipeline operator (|) to pass the CmdletInfo object to the Where-Object cmdlet, which examines the definition (syntax) of each object ($_) for a value that includes “first”.

    The result shows that the First parameter belongs to the Select-Object cmdlet.

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

    C:\PS>Get-Command dir | Format-List

    Name             : dir
    CommandType     : Alias
    Definition        : Get-ChildItem
    ReferencedCommand : Get-ChildItem
    ResolvedCommand : Get-ChildItem

    Description
    ———–
    This example shows how to use the Get-Command cmdlet with an Alias. Although it is typically used on cmdlets, Get-Command also displays information about the code in scripts, Functions, Aliases, and executable files.

    This command displays the “dir” Alias in the current console. The command pipes the result to the Format-List cmdlets.

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

    C:\PS>Get-Command notepad

    CommandType     Name         Definition
    ———–     —-         ———-
    Application     notepad.exe    C:\WINDOWS\system32\notepad.exe
    Application     NOTEPAD.EXE    C:\WINDOWS\NOTEPAD.EXE

    Description
    ———–
    This example shows how to use Get-Command to determine which command Windows PowerShell runs when it has access to multiple commands with the same name. When you use the Name parameter without wildcard characters, Get-Command lists the commands with that name in execution precedence order.

    This command shows which Notepad program Windows PowerShell runs when you type “Notepad” without a fully qualified path. The command uses the Name parameter without wildcard characters.

    The sample output shows the Notepad commands in the current console. It indicates that Windows PowerShell will run the instance of Notepad.exe in the C:\Windows\System32 directory.

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

    C:\PS>(Get-Command Get-Date).pssnapin

    C:\PS> (Get-Command remove-gpo).module

    Description
    ———–
    These commands show how to find the snap-in or module from which a particular cmdlet originated.

    The first command uses the PSSnapin property of the CmdletInfo object to find the snap-in that added the Get-Date cmdlet.

    The second command uses the Module property of the CmdletInfo object to find the module that added the Remove-GPO cmdlet.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113309
    about_command_precedence
    Get-Help
    Get-PSDrive
    Get-Member
    Import-PSSession
    Export-PSSession