On this page

PowerShell Event Logs: Complete Guide to Get-WinEvent

Updated on June 18, 2026

Enrico Hochkoeppler Profile

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:

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:

Application Logs​

Applications write their events to this log. The specific events depend on the application, but common sources include:

Security Logs​

The Security log records security-related events and is protected by the operating system. Reading this log requires administrative privileges. Events include:

PowerShell Operational Logs​

PowerShell maintains its own logs under Microsoft-Windows-PowerShell/Operational. These logs are essential for auditing administrative activity and include:

Application and Services Logs​

These are modern ETW logs created by various Windows components and applications. Examples include:

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:

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:

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:

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:

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!

Buy Me a Coffee

Previous

Managing Windows Systems

Next

Scheduled Tasks