PoshCode Archive  Artifact [453eaa87f5]

Artifact 453eaa87f54243377564ff29f832fba9be3da3d9f693c244e19acf8c714778f8:

  • File Check-amp-reboot-Appassure.ps1 — part of check-in [bf2833eec6] at 2018-06-10 13:55:57 on branch trunk — 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. (user: JeffH size: 1361)

# encoding: ascii
# api: powershell
# title: Check & 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
}