# encoding: ascii
# api: powershell
# title: Windows Backup Check
# description: Powershell script to verify if Windows Backup has finished sucessfully or not. On error or warning it sends an email with the server name and the error/warning. On success it does nothing (means the backup finished successfully)
# version: 0.1
# type: script
# author: Paulo Seabra
# license: CC0
# x-poshcode-id: 6519
# x-archived: 2016-10-31T13:09:14
# x-published: 2016-09-14T16:43:00
#
#
#Powershell Script Made by Paulo Seabra. Use it freely, but please give proper credits.

# Set Session variables
$Computer=hostname
$Events=Get-EventLog -LogName Application -EntryType Warning,Error -Source Microsoft-Windows-Backup -After (Get-Date).AddHours(-24)

# Set email parameters
$PSEmailServer = "fqdn of email server"
$EmailFrom="youremail@yourdomain.xx"
$EmailTo="youremail@yourdomain.xx"
$EmailSubject="Backup - $Computer"


# Build body Error/Warning Messages
$EmailBody="<html><head><meta http-equiv=`"Content-Type`" content=`"text/html; charset=utf-8`"></head>"+ $Computer + "<br><br>"
If (!$Events) {exit}
foreach ($Event in $Events){
if ($Events)
{    $Emailbody = $Emailbody + $Event.message + "<br>" +"<br>"}
}

Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -Body $EmailBody -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8)
