← script library

System Event Log Monitor

Monitoring & HealthDecember 27, 2024

This PowerShell script is designed to monitor the Windows system event logs for specified event IDs and report any occurrences. System administrators can use this tool to quickly identify critical events that may need attention, improving their capability to respond to issues efficiently. When utilized alongside ServerEngine, this monitoring script helps maintain a healthy server environment and enhances operational visibility.

powershell
param (
    [int[]]$eventIdsToMonitor = @(6005, 6006, 1014),  # Example event IDs for system startup and shutdown
    [string]$outputFilePath = "C:\EventLogMonitor.csv"
)
# Initialize an array to store log entries
$eventLogEntries = @()
foreach ($eventId in $eventIdsToMonitor) {
    # Get the specific events from System log
    $events = Get-WinEvent -LogName System | Where-Object { $_.Id -eq $eventId }
    foreach ($event in $events) {
        $eventLogEntries += [PSCustomObject]@{
            TimeCreated = $event.TimeCreated
            EventId = $event.Id
            Message = $event.Message
        }
    }
}
# Export the events to a CSV file
$eventLogEntries | Export-Csv -Path $outputFilePath -NoTypeInformation
Write-Output "Event log monitoring completed. Report saved to $outputFilePath."

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.