Using Get-EventLog in PowerShell

The Get-EventLog cmdlet allows you to view event logs directly in your PowerShell terminal, similar to using Event Viewer.

Below are some quick examples to get started:
1. List Available Event Log Types
2. Show Events by Count
3. Filter Events by Message
4. View Full Message of an Event

1. List Available Event Log Types

# Get List of Event Logs Available
Get-EventLog -List
get event log types example

2. Show Events by Count

# Show Events by Count
Get-EventLog -LogName Application | Group-Object -Property Source -NoElement | Sort-Object -Property Count -Descending
get application events by count

3. Filter Events by Message

Retrieve the 10 newest events containing “MSSQLSERVER” in the message:

# Show Events by Message Name
Get-EventLog -LogName Application -Newest 10 -Message *MSSQLSERVER*
show recent eventlog entries for sql server

4. View Full Message of an Event

Display the full message of the most recent event containing “MSSQLSERVER”:

# Show Full Message of an Event
Get-EventLog -LogName Application -Newest 1 -Message *MSSQLSERVER* | Select Message
show recent sql server events

Hope some of this was useful for you!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts
Categories
Tags

Always On Availability Groups (AAG) (4) AWS (4) AWS Redshift (6) Certificates & Encryption (3) Change Data Capture (CDC) (2) Database Admin (72) Database Backups & Recovery (14) Database Mirroring (2) Deleting Data (1) Error Messages (5) Git Commands (6) Importing & Exporting Data (2) Linked Servers (3) Linux Admin (2) Logging & Monitoring (1) Measuring Databases (10) Microsoft Patching (2) MySQL (4) Postgres (6) PowerShell Scripts (1) SQL Server Agent (5) SQL Server Database Files (1) SQL Server Data Types (2) SQL Server Management Studio (SSMS) (15) SQL Server Network Connectivity (3) SQL Server on Linux (1) SQL Server Patching (2) SQL Server Performance (6) SQL Server Permissions (2) SQL Server Processes (SPIDs) (7) SQL Server Replication (2) SQL Server Scripts (13) Windows Admin (21) Windows Authentication (2) Windows Automation (1) Windows Events (2) Windows Firewall (4) Windows Subsystem for Linux (WSL) (18)