Created
May 2, 2020 12:13
-
-
Save dimiboy/7a3a38a0b6c7886df4214c26b36490e3 to your computer and use it in GitHub Desktop.
Windows Backup Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################## | |
# # | |
# Author: Dima K. # | |
# YouTube: https://youtube.com/c/dimustech # | |
# # | |
######################################################## | |
$SendMail = $true | |
$from = "[email protected]" | |
$pass = "MY-PASSWORD" | |
$to = ("[email protected]", "[email protected]") | |
$SmtpServer = "smtp.mail.ru" | |
$backuptarget = "\\qnap\Windows-Backup" | |
#================================================================================================ | |
$secpasswd = (ConvertTo-SecureString "$pass" -AsPlainText -Force) | |
$mycreds = New-Object System.Management.Automation.PSCredential ($from, $secpasswd) | |
$out = (wbadmin start backup -backuptarget:$backuptarget -allcritical -quiet) | |
$backupdate = get-date | |
$outstring = $out | out-string | |
if($out -contains "The backup operation successfully completed.") #Success | |
{ | |
if ($SendMail) | |
{ | |
$Subject = "Windows backup succeeded" | |
$Body = "Windows backup succeeded at $backupdate `n`n $outstring" | |
Send-MailMessage -To $to -From $from -Subject $Subject -Body $Body -SmtpServer $SmtpServer -UseSsl -credential $mycreds | |
exit 0 | |
}else { | |
exit 0 | |
} | |
}else{ #Failed | |
if ($SendMail) | |
{ | |
$Subject = "Windows backup Failed" | |
$Body = "Windows backup Failed at $backupdate `n`n $outstring" | |
Send-MailMessage -To $to -From $from -Subject $Subject -Body $Body -SmtpServer $SmtpServer -UseSsl -credential $mycreds | |
exit 1 | |
}else { | |
exit 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment