Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#SQL Log monitor script
#Query DB, Select any events that match error code 3047 in last 5 minutes. If any match, restart service, else do nothing.
$database = '.\log.db3'
[datetime]$enddate = Get-Date -Format f
$startdate = $date.AddMinutes(-5)
#Query the DB
$query = Invoke-SqliteQuery -Datasource $database -Query "SELECT TimeStamp,ErrorCode FROM LOG WHERE errorcode = '3047'"
#Filter for records in our time range
$result = Where-Object {[datetime]$query.datetime -ge $startdate -and [datetime]$query.datetime -lt $enddate}
if ($result -ne $null){restart-service EmailRobot}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.