# encoding: ascii
# api: powershell
# title: Check &amp; reboot Appassure
# description: Our Appassure backup service will periodically hang and stop taking scheduled snapshots. This script  runs on the Appassure server as a scheduled task every 15 minutes. If the last snapshot job is older than 75 minutes (a value that takes into account the less frequent snapshots that take place over the weekend) it sends an email alert and reboots the server. ‘ScriptEvents’ is an event log I created on teh Appassure server to log these automatic reboots.
# version: 0.1
# type: script
# author: JeffH
# license: CC0
# x-poshcode-id: 5483
# x-archived: 2015-02-20T16:23:23
# x-published: 2015-10-03T18:25:00
#
#
$LastEvent = Get-EventLog AppAssure -newest 1
$TimeCheck = Get-EventLog AppAssure -After (Get-Date).AddMinutes(-75)
If ($TimeCheck -eq $null)
{
$EmailFrom = "jeff@example.com"
$EmailTo = "jeff@example.com"
$Subject = "AppAssure has hung - last event was at " + $LastEvent.TimeGenerated
$Body = "AppAssure has hung - last event was at " + $LastEvent.TimeGenerated
$SMTPServer = "mail.example.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Write-EventLog -LogName ScriptEvents -Source AppAssureHung -EventId 99 -Message $Body
Restart-Computer -Force
}
