PoshCode Archive  Artifact [6d36d720d7]

Artifact 6d36d720d7ed433a362f064ddc89eb64aebdf7d4f7fc5e6704dfb37196444fd2:

  • File Windows-Backup-Check.ps1 — part of check-in [ff08a64909] at 2018-06-10 14:17:11 on branch trunk — 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) (user: Paulo Seabra size: 1379)

# 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)