Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # VM names separated by commas
  2. $VMNames = “Win2003”
  3. # vCenter name/IP
  4. $HostName = “HYPERV”
  5. # Directory that VM backups should go to
  6. $Directory = “\\10.69.70.203\Backup\HYPERV\VEEAM”
  7. # Desired compression level, following compression level from Veeam (Optional)
  8. $CompressionLevel =4
  9. # Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
  10. $EnableQuiescence = $True
  11. # Protect resulting backup with encryption key (Optional; $True/$False)
  12. $EnableEncryption = $False
  13. # Encryption Key (Optional; path to a secure string, C:\SecureString.txt”
  14. $EncryptionKey = “”
  15. # Retention settings (Optional; By default, VeeamZIP files are not removed and kept in the specified location for an indefinite period of time.
  16. # Possible values: Never , Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month)
  17. $Retention = “In2Weeks”
  18. # Email Settings
  19. # Enable notification (Optional)
  20. $EnableNotification = $True
  21.  
  22. # Email notification
  23. $EnableNotification = $True
  24. $to = "XXXX"
  25. $username = "XXXX"
  26. $smtp_server = "smtp.gmail.com"
  27. $port = 587
  28.  
  29. #TLS 587, SSL 465
  30.  
  31. $message = New-Object System.Net.Mail.MailMessage
  32. $message.from = $username
  33. $message.to.add($to)
  34. $message.IsBodyHTML = $true
  35.  
  36.  
  37.  
  38. ##################################################################
  39. # End User Defined Variables
  40. ##################################################################
  41. #################### DO NOT MODIFY PAST THIS LINE ################
  42. Asnp VeeamPSSnapin
  43. $Server = Get-VBRServer -name $HostName
  44. $mbody = @()
  45. foreach ($VMName in $VMNames)
  46. {
  47. $VM = Find-VBRHvEntity -Name $VMName -Server $Server
  48. $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
  49. If ($EnableNotification)
  50. {
  51. $TaskSessions = $ZIPSession.GetTaskSessions()
  52. $FailedSessions = $TaskSessions | where {$_.status -eq “EWarning” -or $_.Status -eq “EFailed”}
  53. if ($FailedSessions -ne $Null)
  54. {
  55. $mbody = $mbody + ($ZIPSession | Select-Object @{n=”Name”;e={($_.name).Substring(0, $_.name.LastIndexOf(())}} ,@{n=”Start Time”;e={$_.CreationTime}},@{n=”End Time”;e={$_.EndTime}},Result,@{n=”Details”;e={$FailedSessions.Title}})
  56. }
  57. Else
  58. {
  59. $mbody = $mbody + ($ZIPSession | Select-Object @{n=”Name”;e={($_.name).Substring(0, $_.name.LastIndexOf(())}} ,@{n=”Start Time”;e={$_.CreationTime}},@{n=”End Time”;e={$_.EndTime}},Result,@{n=”Details”;e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
  60. }
  61. }
  62. }
  63.  
  64. if($EnableNotification){
  65. $subject = "VEEAM Backup status: $Company $HostName"
  66. $message.subject = $subject
  67. $body = "$Company $HostName Veeam backup status: <br>
  68. Info: $MessagyBody <br><br>
  69. Best Regards, <br>
  70. Cone Support
  71. "
  72. $message.body = $body
  73. $smtp = New-Object System.Net.Mail.SmtpClient($smtp_server, $port);
  74. $smtp.EnableSSL = $true
  75. $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $password);
  76. $smtp.send($message)
  77.  
  78.  
  79. Write-Host E-mail has been sent to $to
  80. Write-Host From: $username Server: $smtp_server Port: $port
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement