Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # create password file with 'read-host -assecurestring | convertfrom-securestring | out-file C:\gmailSecureString.txt'
- # For gmail, enable 'insecure' authentication
- $ErrorId = 5
- $SuccessId = 14
- $MaxRetry = 2
- $From = "YourEmail@gmail.com"
- $To = "YourEmail@gmail.com"
- $SMTPServer = "smtp.gmail.com"
- $SMTPPort = "587"
- $PasswordSecureString = cat C:\gmailSecureString.txt | ConvertTo-SecureString
- $Credentials = new-object -TypeName System.Management.Automation.PSCredential -ArgumentList $From, $PasswordSecureString
- $Errors = "none"
- for($i=0; $i -le $MaxRetry; $i++){
- try{
- wbAdmin Start Backup -backupTarget:"I:" -include:"C:,M:" -allCritical -quiet
- $i = $maxRetry
- }catch{
- $Errors = $_
- }
- }
- $Results = Get-WinEvent -LogName Microsoft-Windows-Backup -MaxEvents 1
- if($Results.Id -eq $SuccessId -and $Error -eq "none") {
- $Subject = "Backup Success"
- } else {
- $Subject = "Backup Failed!"
- }
- $Body = ""
- $Body = $Body + ($Results | Format-Table | Out-String)
- $Body = $Body + "\r\n" + $Errors
- Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $Credentials
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement