Export (0) Print
Expand All

Get-Event

Published: February 29, 2012

Updated: August 15, 2012

Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0

Get-Event

Gets the events in the event queue.

Syntax

Parameter Set: BySource
Get-Event [[-SourceIdentifier] <String> ] [ <CommonParameters>]

Parameter Set: ById
Get-Event [-EventIdentifier] <Int32> [ <CommonParameters>]




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

Gets only the events with the specified event identifier.


Aliases

none

Required?

true

Position?

1

Default Value

none

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.


Aliases

none

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, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • None

    You cannot pipe input to this cmdlet.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • 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 $EventArgs 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 $Args 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.

Examples

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

This command gets all events in the event queue.


PS C:\> get-event

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

This command gets events in which the value of the SourceIdentifier property is "PowerShell.ProcessCreated".


PS C:\> get-event -sourceIdentifier "PowerShell.ProcessCreated"

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

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.


PS C:\> $events = get-event
PS C:\>$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      :

PS C:\>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      :

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

This command gets the event with an event identifier of 2.


PS C:\> get-event -eventIdentifier 2

Related topics



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft