
Richard Burt (AIPSO) asked a question.
Event ID monitoring
HI -
I have a PowerShell script to monitor 3 event ids and send an alert if its true it doesn't work when I add it to wug but works locally on the server.
$LogName = "Application"
$EventIDs = @(431, 403)
$MaxEventsToCheck = 20
$MatchingEvents = @()
foreach ($id in $EventIDs) {
$events = Get-WinEvent -FilterHashtable @{LogName=$LogName; ID=$id} -MaxEvents $MaxEventsToCheck -ErrorAction SilentlyContinue
$MatchingEvents += $events
}
if ($MatchingEvents.Count -gt 0) {
$ids = ($MatchingEvents | Select-Object -ExpandProperty Id -Unique) -join ", "
$Context.SetResult(1, "Found matching Event ID(s): $ids")
} else {
$Context.SetResult(0, "No matching Event IDs found.")
}
I fixed it for you to work getting the Event Log from a remote machine in WUG.
Create a PowerShell Active Monitor, copy-paste the code above in to the script block. Save it, apply to devices.