Created
April 25, 2019 21:26
-
-
Save nshores/1dca732eb5de90ce78b9e9fe5b9e77b6 to your computer and use it in GitHub Desktop.
sql_log_monitor
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
#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