Tag: wbadmin.msc

K.I.S.S. Windows Server Backup Failure Notification Powershell script

by on May.03, 2018, under Code, Posts

$value = get-wbsummary | select -expandproperty lastbackupresulthr

if ( $value -ne 0 )
{
$EmailFrom = “YourGmailAccount@gmail.com”
$EmailTo = “WhoYouWantTonotify@domain.com”
$Subject = “Notification from Windows Server Backup”
$Body = “Last backup may have failed…”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“YourGmailAccount”, “yourcleartextpassword”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}

The code is pretty self explanatory. (The main block I just found from howtogeek.com) Granted it is not secure because it’s storing a cleartext password. You can save this in a .ps1 file and create a scheduled task that runs with at least admin privileges (the function ‘get-wbsummary’ requires admin rights) after a backup has ran.

The $EmailTo variable you could use an SMS gateway to get a text notification. (See this list.) For instance if your phone number is 6165559876 and you have Verizon, it would look like this: $EmailTo = 6165559876@vtext.com.

Leave a Comment :, , , , , , , , , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!