Created
April 9, 2021 11:14
-
-
Save iyevhen/bac257ca30fc5d07beea26ce563c04e8 to your computer and use it in GitHub Desktop.
Query All Event Logs for recent events for last hour using PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$old = (Get-Date).AddHours(-1) | |
$before_lines = 50 | |
$after_lines = 50 | |
Write-Host "Pulling Warn/Error Windows Events started >= $old" | |
Get-WinEvent -ListLog * -EA silentlycontinue | | |
Where-Object { $_.recordcount -AND $_.lastwritetime -gt $old } | | |
ForEach-Object { get-winevent -FilterHashtable @{LogName=$_.logname; StartTime=$old } -EA silentlycontinue } | | |
Sort-Object TimeCreated | | |
Format-List TimeCreated, LevelDisplayName, ProviderName, Message | | |
Out-String -Stream -Width 1000 | | |
Select-String -Pattern 'LevelDisplayName\s+:\s+Error.*','LevelDisplayName\s+:\s+Warning.*' -Context $before_lines,$after_lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment