Get Event - PowerShell
Overview
Get-Event retrieves events raised by PowerShell modules. Event objects contain information about an incident (error, warning, or informational message) that occurred within the scope of the PowerShell session.
Syntax
Get-Event [-ListSource] [-ListChannel] [-Source <string>] [-Channel <string>]
[-Skip] [-Count <int>] [-Include] [-Exclude] [-Newest] [-Oldest]
[<CommonParameters>]
Options/Flags
- -ListSource: Lists the event sources available in the current session.
- -ListChannel: Lists the event channels available from the specified source.
- -Source: Filters events based on the specified source name.
- -Channel: Filters events based on the specified channel name.
- -Skip: Number of events to skip from the beginning of the collection.
- -Count: Maximum number of events to retrieve.
- -Include: Array of event levels to include in the results.
- -Exclude: Array of event levels to exclude from the results.
- -Newest: Returns the most recent events first.
- -Oldest: Returns the oldest events first.
Examples
Example 1: Retrieve all events
Get-Event
Example 2: Filter events by level and source
Get-Event -Include Error,Warning -Source Microsoft-PowerShell
Example 3: Retrieve events from a specific channel
Get-Event -Source Microsoft-PowerShell -Channel WinRM
Common Issues
Error: Event not found.
Solution: The specified source or channel may not exist. Ensure the correct names are used.
Integration
Combine with Where-Object to filter events based on specific criteria:
Get-Event | Where-Object { $_.Level -eq "Error" }