{"id":1434,"date":"2018-05-03T11:28:33","date_gmt":"2018-05-03T16:28:33","guid":{"rendered":"http:\/\/zitstif.no-ip.org\/?p=1434"},"modified":"2018-05-03T11:41:54","modified_gmt":"2018-05-03T16:41:54","slug":"kiss-windows-server-backup-failure-notification-powershell-script","status":"publish","type":"post","link":"http:\/\/zitstif.no-ip.org\/?p=1434","title":{"rendered":"K.I.S.S. Windows Server Backup Failure Notification Powershell script"},"content":{"rendered":"<p><strong>$value = get-wbsummary | select -expandproperty lastbackupresulthr<\/strong><\/p>\n<p><strong>if ( $value -ne 0 )<\/strong><br \/>\n<strong> {<\/strong><br \/>\n<strong> $EmailFrom = &#8220;YourGmailAccount@gmail.com&#8221;<\/strong><br \/>\n<strong> $EmailTo = &#8220;WhoYouWantTonotify@domain.com&#8221;<\/strong><br \/>\n<strong> $Subject = &#8220;Notification from Windows Server Backup&#8221;<\/strong><br \/>\n<strong> $Body = &#8220;Last backup may have failed&#8230;&#8221;<\/strong><br \/>\n<strong> $SMTPServer = &#8220;smtp.gmail.com&#8221;<\/strong><br \/>\n<strong> $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)<\/strong><br \/>\n<strong> $SMTPClient.EnableSsl = $true<\/strong><br \/>\n<strong> $SMTPClient.Credentials = New-Object System.Net.NetworkCredential(&#8220;YourGmailAccount&#8221;, &#8220;yourcleartextpassword&#8221;);<\/strong><br \/>\n<strong> $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)<\/strong><br \/>\n<strong> }<\/strong><\/p>\n<p>The code is pretty self explanatory. (The main block I just found from <a href=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2012\/07\/Sample.txt\" target=\"_blank\" rel=\"noopener\">howtogeek.com<\/a>) Granted it is not secure because it&#8217;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 &#8216;get-wbsummary&#8217; requires admin rights) after a backup has ran.<\/p>\n<p>The <strong>$EmailTo<\/strong> variable you could use an SMS gateway to get a text notification. (See this <a href=\"https:\/\/teamunify.uservoice.com\/knowledgebase\/articles\/57460-communication-email-to-sms-gateway-list\" target=\"_blank\" rel=\"noopener\">list<\/a>.) For instance if your phone number is 6165559876 and you have Verizon, it would look like this: <strong>$EmailTo = 6165559876@vtext.com<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>$value = get-wbsummary | select -expandproperty lastbackupresulthr if ( $value -ne 0 ) { $EmailFrom = &#8220;YourGmailAccount@gmail.com&#8221; $EmailTo = &#8220;WhoYouWantTonotify@domain.com&#8221; $Subject = &#8220;Notification from Windows Server Backup&#8221; $Body = &#8220;Last backup may have failed&#8230;&#8221; $SMTPServer = &#8220;smtp.gmail.com&#8221; $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential(&#8220;YourGmailAccount&#8221;, &#8220;yourcleartextpassword&#8221;); $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body) } &hellip; <a href=\"http:\/\/zitstif.no-ip.org\/?p=1434\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">K.I.S.S. Windows Server Backup Failure Notification Powershell script<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3],"tags":[458,936,937,940,942,938,933,943,944,941,934,939,935],"class_list":["post-1434","post","type-post","status-publish","format-standard","hentry","category-code","category-posts","tag-backup","tag-email","tag-gmail","tag-howtogeek","tag-k-i-s-s","tag-notification","tag-powershell","tag-sms","tag-text","tag-wbadmin-msc","tag-windows-server","tag-windows-server-2016-backup-email-notification-failure","tag-windows-server-backup"],"_links":{"self":[{"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/posts\/1434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1434"}],"version-history":[{"count":7,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/posts\/1434\/revisions"}],"predecessor-version":[{"id":1442,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/posts\/1434\/revisions\/1442"}],"wp:attachment":[{"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1434"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}