Get-EventLog is a Windows PowerShell 5.1 cmdlet. It is not part of PowerShell 7, and the command to use in its place is Get-WinEvent:
Get-WinEvent -LogName Application -MaxEvents 10
On Windows, PowerShell 7 will still run Get-EventLog by loading it through the Windows PowerShell compatibility session, so an old script may keep working. It only reads the classic logs, though, and it cannot filter at the source. Below are the common Get-EventLog commands and what to write in their place. Get-WinEvent works the same in Windows PowerShell 5.1, so these run in either.

List the Event Logs
The old Get-EventLog -List becomes:
Get-WinEvent -ListLog * -ErrorAction SilentlyContinue |
Where-Object RecordCount -gt 0 |
Sort-Object RecordCount -Descending |
Select-Object LogName, RecordCount -First 10This shows the per-component Microsoft-Windows-* logs as well as Application, System and Security, which Get-EventLog cannot see. Security needs an elevated window. Check If PowerShell Is Running as Administrator shows how to check which one you are in.
Count Events by Source
Get-WinEvent -LogName Application -MaxEvents 1000 |
Group-Object ProviderName -NoElement |
Sort-Object Count -DescendingWhat Get-EventLog calls the Source, Get-WinEvent calls the ProviderName. -MaxEvents keeps it to the newest 1000 records, because the whole Application log can be tens of thousands.
Filter by Source or Message
Get-EventLog -Message has no direct match. If what you are after is one source, filter on the provider, which the event log service does for you and is fast:
Get-WinEvent -FilterHashtable @{ LogName = 'Application'; ProviderName = 'MSSQLSERVER' } -MaxEvents 10If you really need to search the message text, do it after a time filter, so you are not reading the whole log:
Get-WinEvent -FilterHashtable @{ LogName = 'Application'; StartTime = (Get-Date).AddDays(-7) } |
Where-Object Message -like '*MSSQLSERVER*' |
Select-Object -First 10 TimeCreated, Id, ProviderNameIf SQL Server is why you are in the Application log, Check When SQL Server Was Last Restarted on sqldba.blog uses the same events.
Show the Full Message
Get-WinEvent -FilterHashtable @{ LogName = 'Application'; ProviderName = 'MSSQLSERVER' } -MaxEvents 1 |
Select-Object -ExpandProperty Message-ExpandProperty prints the text on its own, without the column cutting it short. Format-List shows it with the other properties.
Parameter and Property Names
-Newest 10becomes-MaxEvents 10.-SourcebecomesProviderNamein the filter hashtable.-EntryType ErrorbecomesLevel = 2in the filter hashtable (1 Critical, 2 Error, 3 Warning, 4 Information).-AfterbecomesStartTimein the filter hashtable.EventID,EntryType,TimeGeneratedon the output becomeId,LevelDisplayName,TimeCreated.
One difference to expect in scripts: when nothing matches, Get-WinEvent -FilterHashtable raises No events were found that match the specified selection criteria as an error. Add -ErrorAction SilentlyContinue where an empty result is normal. How to Show Event Logs in PowerShell goes further into filtering, remote machines and the slow and fast ways to filter.
The Original Get-EventLog Commands
If you are on Windows PowerShell 5.1 and only need the classic logs, these still work as they always did.
Get-EventLog -List

Get-EventLog -LogName Application | Group-Object -Property Source -NoElement | Sort-Object -Property Count -Descending

Get-EventLog -LogName Application -Newest 10 -Message *MSSQLSERVER*

Get-EventLog -LogName Application -Newest 1 -Message *MSSQLSERVER* | Select-Object Message

Related
If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.
Leave a Reply