Advertisement
Guest User

Untitled

a guest
Apr 7th, 2017
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. Computer Management
  2. System Tools
  3. Event Viewer
  4. Application and Services Logs
  5. Microsoft
  6. Windows
  7. Task Scheduler
  8. Operational
  9.  
  10. $ScheduledTaskName = "HansBackup"
  11. $Result = (schtasks /query /FO LIST /V /TN $ScheduledTaskName | findstr "Result")
  12. $Result = $Result.substring(12)
  13. $Code = $Result.trim()
  14.  
  15. If ($Code -gt 0) {
  16. $User = "mymail@gmail.com"
  17. $Pass = ConvertTo-SecureString -String "myPassword" -AsPlainText -Force
  18. $Cred = New-Object System.Management.Automation.PSCredential $User, $Pass
  19. ################################################################################
  20.  
  21. $From = "Alert Scheduled Task <mymail@gmail.com>"
  22. $To = "Me Gmail <mymail@gmail.com>"
  23. $Subject = "Scheduled task 'Backup' failed"
  24. $Body = "Error code: $Code"
  25. $SMTPServer = "smtp.gmail.com"
  26. $SMTPPort = "587"
  27.  
  28. Send-MailMessage -From $From -to $To -Subject $Subject `
  29. -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
  30. -Credential $Cred
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement