Skip to content

Instantly share code, notes, and snippets.

@nshores
Created April 25, 2019 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshores/1dca732eb5de90ce78b9e9fe5b9e77b6 to your computer and use it in GitHub Desktop.
Save nshores/1dca732eb5de90ce78b9e9fe5b9e77b6 to your computer and use it in GitHub Desktop.
sql_log_monitor
#SQL Log monitor script
# http://ramblingcookiemonster.github.io/SQLite-and-PowerShell/
#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