- Courses
- đź’»Programming Languages
- 🪟PowerShell
- PowerShell for System Administration
- Managing Windows Systems
- Event Logs
On this page
PowerShell Event Logs: Complete Guide to Get-WinEvent
Updated on June 18, 2026
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
Windows event logs are the primary source of diagnostic and security information on any Windows system. PowerShell provides the Get-WinEvent cmdlet, which is the modern, supported method for querying event logs, including classic logs like System and Application, as well as modern Event Tracing for Windows (ETW) logs. The older Get-EventLog cmdlet uses the deprecated Win32 API, is not supported in PowerShell 7, and should be avoided in favor of Get-WinEvent. Get-WinEvent enables powerful filtering using hash tables, XPath, or XML queries, making it an essential tool for system administrators, security analysts, and anyone who needs to investigate Windows system behavior.
Understanding the Windows Event Log System​
Windows organizes events into structured logs, each containing entries generated by different components of the operating system and applications. Every event includes standardized metadata that enables precise filtering and analysis.
The key properties of any event log entry include:
- Event ID — a numeric identifier describing the type of event, which is often the most useful filter for specific issues
- Provider Name — the component or application that generated the event
- Level — severity classification (Information, Warning, Error, Critical, Verbose)
- TimeCreated — timestamp indicating when the event occurred
- Message — a human-readable description containing detailed diagnostic information
Get-WinEvent can retrieve events from both classic logs (such as System and Application) and modern ETW logs introduced with Windows Vista. By default, Get-WinEvent returns events in chronological order from newest to oldest.
Classic Logs vs. Modern Event Logs​
Windows Vista introduced a new Windows Event Log technology that provides enhanced capabilities over the classic log system. Get-EventLog only works with the classic logs and uses the outdated Win32 API. Get-WinEvent works with both classic and modern logs, making it the comprehensive solution.
Important: Get-EventLog is no longer supported in PowerShell 7 and later. All new scripts and administration tasks should use Get-WinEvent.
Types of Event Logs​
Windows maintains several categories of logs, each serving a distinct purpose. Understanding these categories helps you know where to look for specific types of information.
System Logs​
The System log records events generated by core operating system components. This is the first place to check when diagnosing system-level problems. Events in this log include:
- Driver failures and hardware issues
- Service startup, shutdown, and failures
- Kernel events and system crashes
- File system and storage issues
Application Logs​
Applications write their events to this log. The specific events depend on the application, but common sources include:
- SQL Server database events
- Internet Information Services (IIS) web server events
- .NET runtime events
- Third-party software diagnostics
Security Logs​
The Security log records security-related events and is protected by the operating system. Reading this log requires administrative privileges. Events include:
- Successful and failed logon attempts (Event ID 4624 and 4625)
- Privilege use and user rights assignments
- Access control changes to files, registry keys, and other objects
- Policy modifications and group policy events
- Account management activities (user creation, deletion, group membership changes)
PowerShell Operational Logs​
PowerShell maintains its own logs under Microsoft-Windows-PowerShell/Operational. These logs are essential for auditing administrative activity and include:
- Script block execution (Event ID 4104)
- Remote session connections and disconnections
- Module loading and unloading
- PowerShell errors and warnings
Application and Services Logs​
These are modern ETW logs created by various Windows components and applications. Examples include:
Microsoft-Windows-WinRM/Operational— WinRM and PowerShell Remoting eventsMicrosoft-Windows-Windows Defender/Operational— Windows Defender eventsOpenSSH/Operational— OpenSSH server eventsMicrosoft-Windows-Kernel-General— kernel-level events
To see all available logs on a system:
Get-WinEvent -ListLog *
Code explanation: The -ListLog parameter with the wildcard * returns every event log on the local computer, including classic and modern logs. The output includes each log's name, size, and record count.
Retrieving Event Logs with Get-WinEvent​
Get-WinEvent provides multiple parameter sets for different query scenarios. The most commonly used approaches are:
Reading from a Specific Log​
The simplest query uses -LogName to specify the log and -MaxEvents to limit results:
Get-WinEvent -LogName "System" -MaxEvents 20
Code explanation: This retrieves the 20 most recent events from the System log. -MaxEvents ensures the command returns quickly even on logs with millions of entries. By default, results are returned from newest to oldest.
Listing All Logs with Metadata​
To get detailed information about each log, including its size and record count:
Get-WinEvent -ListLog * | Select-Object LogName, RecordCount, MaximumSizeInBytes
Code explanation: This command lists every log along with its current event count and maximum size. The RecordCount property can be null (zero) for some logs.
Reading from Modern ETW Logs​
Modern logs have longer, more descriptive names:
Get-WinEvent -LogName "Microsoft-Windows-PowerShell/Operational" -MaxEvents 10
Code explanation: This retrieves the 10 most recent events from the PowerShell Operational log, which is essential for auditing script execution and remoting activity.
Filtering Events with FilterHashtable​
The FilterHashtable parameter is the most efficient way to filter events. When a query uses FilterHashtable, performance improves significantly because filtering happens at the source rather than after retrieving all events.
Filtering by Event ID​
Event IDs are often the most specific and useful filter. For example, to find all instances of a particular system event:
Get-WinEvent -FilterHashtable @{
LogName = "System"
Id = 7036
}
Code explanation: The hash table uses key-value pairs. The LogName key specifies the log, and the Id key specifies the event ID. This retrieves only events with ID 7036 (service start/stop notifications) from the System log.
Filtering by Time Range​
To restrict results to a specific time window, use StartTime and EndTime:
Get-WinEvent -FilterHashtable @{
LogName = "Application"
StartTime = (Get-Date).AddHours(-24)
EndTime = (Get-Date)
}
Code explanation: StartTime and EndTime accept DateTime objects. This example retrieves all Application log events from the last 24 hours. The time range filter is applied at the source, making it extremely efficient even on large logs.
Filtering by Level (Severity)​
The Level key filters by severity level. Common values include:
1— Critical2— Error3— Warning4— Information5— Verbose
To find all errors in the System log:
Get-WinEvent -FilterHashtable @{
LogName = "System"
Level = 2
}
Code explanation: Level 2 corresponds to Error events. This retrieves only error events from the System log, which is useful for focusing on problems rather than informational events.
Filtering by Provider​
To see events from a specific source, use ProviderName:
Get-WinEvent -FilterHashtable @{
ProviderName = "Microsoft-Windows-WinRM"
}
Code explanation: This retrieves all events from the WinRM provider, which is useful when investigating PowerShell Remoting or WS-Management issues.
Combining Multiple Filters​
Multiple keys in the same hash table combine with AND logic:
Get-WinEvent -FilterHashtable @{
LogName = "Security"
Id = 4625
StartTime = (Get-Date).AddHours(-1)
}
Code explanation: This retrieves failed logon attempts (Event ID 4625) from the Security log that occurred within the last hour. Combining LogName, Id, and StartTime creates a precise, efficient query.
Using the Deprecated Get-EventLog​
Get-EventLog remains available in Windows PowerShell 5.1 for backward compatibility, but it is deprecated and not supported in PowerShell 7. It should not be used for new scripts or administration tasks.
Example of Get-EventLog usage (for reference only):
Get-EventLog -LogName System -Newest 5
Code explanation: This retrieves the five most recent entries from the System log. While this works in older versions, the same task should be performed with Get-WinEvent -LogName System -MaxEvents 5.
Key limitations of Get-EventLog:
- Uses the deprecated Win32 API
- Only works with classic logs, not modern ETW logs
- Not supported in PowerShell 7 or later
- Less efficient filtering capabilities
Get-WinEvent is the supported, more capable alternative for all event log operations.
Interpreting Event Log Entries​
Each event object returned by Get-WinEvent has properties that provide structured access to the event data. The most commonly used properties are:
$event = Get-WinEvent -LogName System -MaxEvents 1
$event.Id # Event ID
$event.LevelDisplayName # Severity as a string
$event.TimeCreated # Timestamp
$event.ProviderName # Source of the event
$event.Message # Human-readable description
Code explanation: The first command retrieves the most recent System log event. Subsequent commands access individual properties. The Message property contains the detailed diagnostic information that administrators typically read first.
Understanding the Message Property​
The Message property often contains the most valuable information for troubleshooting. For example, a service failure event might include:
- The service name that failed
- The error code returned by the service
- The path to the service executable
- Contextual information about the failure
When writing automated monitoring scripts, you can search the Message property for specific error codes or patterns.
Practical Administrative Scenarios​
Identifying Recent System Errors​
To find recent system errors for troubleshooting:
Get-WinEvent -FilterHashtable @{
LogName = "System"
Level = 2
} | Select-Object TimeCreated, Id, ProviderName, Message
Code explanation: Level 2 represents Error severity. This retrieves all System log errors, displaying the timestamp, event ID, source, and message. This is the first step in investigating system instability or failures.
Monitoring Failed Logon Attempts​
Security auditing often requires monitoring failed logon attempts:
Get-WinEvent -FilterHashtable @{
LogName = "Security"
Id = 4625
} | Select-Object TimeCreated, @{N='User';E={$_.Properties[5].Value}}, @{N='Source';E={$_.Properties[18].Value}}
Code explanation: Event ID 4625 indicates a failed logon attempt. The Properties array contains structured data about the event. Property 5 contains the username, and property 18 contains the source IP address. This creates a readable report of failed logins.
Auditing PowerShell Script Execution​
To audit PowerShell script execution on a system:
Get-WinEvent -FilterHashtable @{
LogName = "Microsoft-Windows-PowerShell/Operational"
Id = 4104
} | Select-Object TimeCreated, @{N='Script';E={$_.Properties[2].Value}}
Code explanation: Event ID 4104 records script block execution in the PowerShell Operational log. Property 2 contains the script text. This is essential for security auditing and investigating potentially malicious PowerShell activity.
Finding Specific Events Across Multiple Logs​
Get-WinEvent can query multiple logs simultaneously:
Get-WinEvent -FilterHashtable @{
LogName = "System", "Application"
Level = 1, 2
} -MaxEvents 50
Code explanation: The LogName key accepts an array of strings, and Level accepts multiple values. This retrieves the 50 most recent Critical (1) and Error (2) events from both the System and Application logs.
Exporting Event Data​
Event logs can be exported for archival, reporting, or analysis in other tools.
Exporting to CSV​
The most common export format is CSV:
Get-WinEvent -FilterHashtable @{
LogName = "System"
Level = 2, 3
} | Select-Object TimeCreated, Id, LevelDisplayName, ProviderName, Message |
Export-Csv -Path "C:\Logs\SystemErrors.csv" -NoTypeInformation
Code explanation: This filters the System log for Error and Warning events, selects relevant properties, and exports them to a CSV file. The -NoTypeInformation parameter removes the type header that PowerShell adds by default.
Exporting with Custom Date Range​
To export a specific time period:
$start = (Get-Date).AddDays(-7)
$end = Get-Date
Get-WinEvent -FilterHashtable @{
LogName = "Security"
StartTime = $start
EndTime = $end
Id = 4624, 4625
} | Export-Csv -Path "C:\Logs\LogonAudit.csv" -NoTypeInformation
Code explanation: This exports all successful (4624) and failed (4625) logon attempts from the last seven days to a CSV file for security reporting.
Common Mistakes to Avoid​
Using Get-EventLog in PowerShell 7. Get-EventLog is not supported in PowerShell 7 and later. Always use Get-WinEvent for compatibility.
Filtering with Where-Object instead of FilterHashtable. Using Where-Object retrieves all events before filtering, which is inefficient and slow on large logs. FilterHashtable filters at the source and is significantly faster.
Running without administrative privileges when accessing Security logs. The Security log is protected. Running Get-WinEvent without administrator rights results in errors when accessing protected logs.
Assuming Get-EventLog works with modern ETW logs. Get-EventLog only works with classic logs. Modern logs require Get-WinEvent.
Not closing the PowerShell session after remote log queries. When querying remote computers, the session resources are released when the command completes, but persistent sessions should be explicitly closed.
Summary​
Windows event logs provide a detailed and structured record of system activity. PowerShell offers a powerful interface for retrieving, filtering, and analyzing these logs, enabling administrators to diagnose issues, investigate security events, audit administrative actions, and export data for reporting.
The key practices for effective event log management with PowerShell are:
- Use
Get-WinEventfor all event log queries, asGet-EventLogis deprecated and not supported in PowerShell 7 - Apply
FilterHashtablefor efficient, source-side filtering rather than post-retrieval filtering withWhere-Object - Understand the different log types (System, Application, Security, PowerShell Operational, and Application and Services logs) to know where to look
- Use Event IDs and provider names as primary filters for precision
- Export data to CSV for archival, reporting, or analysis in other tools
- Run PowerShell as an administrator when accessing protected logs like Security
By mastering event log management, you gain deep visibility into the behavior of Windows systems and the ability to respond quickly and effectively to operational and security issues.
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Managing Windows Systems
Next
Scheduled Tasks
-
Understanding the Windows Event Log System
- Classic Logs vs. Modern Event Logs
-
Types of Event Logs
- System Logs
- Application Logs
- Security Logs
- PowerShell Operational Logs
- Application and Services Logs
-
Retrieving Event Logs with Get-WinEvent
- Reading from a Specific Log
- Listing All Logs with Metadata
- Reading from Modern ETW Logs
-
Filtering Events with FilterHashtable
- Filtering by Event ID
- Filtering by Time Range
- Filtering by Level (Severity)
- Filtering by Provider
- Combining Multiple Filters
-
Using the Deprecated Get-EventLog
-
Interpreting Event Log Entries
- Understanding the Message Property
-
Practical Administrative Scenarios
- Identifying Recent System Errors
- Monitoring Failed Logon Attempts
- Auditing PowerShell Script Execution
- Finding Specific Events Across Multiple Logs
-
Exporting Event Data
- Exporting to CSV
- Exporting with Custom Date Range
-
Common Mistakes to Avoid
-
Summary
