Monthly Archives: October 2008

WindowsServerBackupEmailStatus

Powershell script for Windows Server 2008.
This script sends out status of any failed Windows Server Backups to a specified e-mail address.
It should be scheduled to run every day since it checks the Backup Event Log for records created the last 24 hours.

# =================================================================================================== 
# WindowsServerBackupEmailStatus.ps1
#
# Created by: Goran Tornqvist. 
# This script is freeware, do what you like with it ;)
# 
# Description: 
# Powershell script for Windows Server 2008.
# This script sends out status of any failed Windows Server Backups to a specified e-mail address.
# It should be scheduled to run every day since it checks the Backup Event Log for records created 
# the last 24 hours. 
# Run using command: powershell.exe WindowsServerBackupEmailStatus.ps1
# ===================================================================================================

$ErrorActionPreference = “SilentlyContinue”

$recs = get-winevent -LogName "Microsoft-Windows-Backup" -FilterXPath "*[System[Level!=4 and TimeCreated[timediff(@SystemTime) <= 86400000]]]"
if ( $recs.Length -gt 0 ) {

  $subject = "Backup errors/warnings exist"
  $body = ""

  for ($i=1; $i -lt $recs.Length; $i++) {
    $body = $body + "Date/Time: " + $recs[$i].TimeCreated + "
Message: " + $recs[$i].Message + "
________________________________________

"
  }

$emailFrom = "admin@yourdomain.com"
$emailTo = "you@yourdomain.com"
$smtpServer = "smtp.yourisp.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)

}