Advertisement
Guest User

Windows System Image PowerShell Script

a guest
Jul 12th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # create password file with 'read-host -assecurestring | convertfrom-securestring | out-file C:\gmailSecureString.txt'
  2. # For gmail, enable 'insecure' authentication
  3.  
  4. $ErrorId = 5
  5. $SuccessId = 14
  6. $MaxRetry = 2
  7.  
  8. $From = "YourEmail@gmail.com"
  9. $To = "YourEmail@gmail.com"
  10. $SMTPServer = "smtp.gmail.com"
  11. $SMTPPort = "587"
  12. $PasswordSecureString = cat C:\gmailSecureString.txt | ConvertTo-SecureString
  13. $Credentials = new-object -TypeName System.Management.Automation.PSCredential -ArgumentList $From, $PasswordSecureString
  14. $Errors = "none"
  15.  
  16. for($i=0; $i -le $MaxRetry; $i++){
  17.     try{
  18.         wbAdmin Start Backup -backupTarget:"I:" -include:"C:,M:" -allCritical -quiet
  19.         $i = $maxRetry
  20.     }catch{
  21.         $Errors = $_
  22.     }
  23. }
  24.  
  25. $Results = Get-WinEvent -LogName Microsoft-Windows-Backup -MaxEvents 1
  26.  
  27. if($Results.Id -eq $SuccessId -and $Error -eq "none") {
  28.     $Subject = "Backup Success"
  29. } else {
  30.     $Subject = "Backup Failed!"
  31. }
  32.  
  33. $Body = ""
  34. $Body = $Body + ($Results | Format-Table | Out-String)
  35. $Body = $Body + "\r\n" + $Errors
  36.  
  37. 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