Skip to content

Instantly share code, notes, and snippets.

@loldot
Created March 3, 2023 12:38
Show Gist options
  • Save loldot/ca24451869ca25460a44094c5bb3ae02 to your computer and use it in GitHub Desktop.
Save loldot/ca24451869ca25460a44094c5bb3ae02 to your computer and use it in GitHub Desktop.
function Get-ApiErrors() {
Get-WinEvent –LogName dbank -MaxEvents 500 `
| Where-Object { $_.LevelDisplayName -eq "Error" } `
| Where-Object { $_.Message -notlike "*LogController*" }
| Format-List -Property TimeCreated,LevelDisplayName,Message
| more
}
function Get-ApiEventTail($ShowExisting=10) {
$LogName = "dbank"
if ($ShowExisting -gt 0) {
$data = Get-WinEvent –LogName $LogName -max $ShowExisting
$data | Format-List -Property TimeCreated,LevelDisplayName,Message
$idx = $data[0].RecordId
}
else {
$idx = (Get-WinEvent –LogName $LogName -max 1).RecordId
}
while ($true)
{
start-sleep -Seconds 1
$idx2 = (Get-WinEvent –LogName $LogName -max 1).RecordId
if ($idx2 -gt $idx) {
Get-WinEvent –LogName $LogName -max ($idx2 - $idx) | Format-List -Property TimeCreated,LevelDisplayName,Message
}
$idx = $idx2
# Any key to terminate; does NOT work in PowerShell ISE!
# if ($Host.UI.RawUI.KeyAvailable) { return; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment