Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # VM names separated by commas
- $VMNames = “Win2003”
- # vCenter name/IP
- $HostName = “HYPERV”
- # Directory that VM backups should go to
- $Directory = “\\10.69.70.203\Backup\HYPERV\VEEAM”
- # Desired compression level, following compression level from Veeam (Optional)
- $CompressionLevel = “4”
- # Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
- $EnableQuiescence = $True
- # Protect resulting backup with encryption key (Optional; $True/$False)
- $EnableEncryption = $False
- # Encryption Key (Optional; path to a secure string, C:\SecureString.txt”
- $EncryptionKey = “”
- # Retention settings (Optional; By default, VeeamZIP files are not removed and kept in the specified location for an indefinite period of time.
- # Possible values: Never , Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month)
- $Retention = “In2Weeks”
- # Email Settings
- # Enable notification (Optional)
- $EnableNotification = $True
- # Email notification
- $EnableNotification = $True
- $to = "XXXX"
- $username = "XXXX"
- $smtp_server = "smtp.gmail.com"
- $port = 587
- #TLS 587, SSL 465
- $message = New-Object System.Net.Mail.MailMessage
- $message.from = $username
- $message.to.add($to)
- $message.IsBodyHTML = $true
- ##################################################################
- # End User Defined Variables
- ##################################################################
- #################### DO NOT MODIFY PAST THIS LINE ################
- Asnp VeeamPSSnapin
- $Server = Get-VBRServer -name $HostName
- $mbody = @()
- foreach ($VMName in $VMNames)
- {
- $VM = Find-VBRHvEntity -Name $VMName -Server $Server
- $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
- If ($EnableNotification)
- {
- $TaskSessions = $ZIPSession.GetTaskSessions()
- $FailedSessions = $TaskSessions | where {$_.status -eq “EWarning” -or $_.Status -eq “EFailed”}
- if ($FailedSessions -ne $Null)
- {
- $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}})
- }
- Else
- {
- $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}})
- }
- }
- }
- if($EnableNotification){
- $subject = "VEEAM Backup status: $Company $HostName"
- $message.subject = $subject
- $body = "$Company $HostName Veeam backup status: <br>
- Info: $MessagyBody <br><br>
- Best Regards, <br>
- Cone Support
- "
- $message.body = $body
- $smtp = New-Object System.Net.Mail.SmtpClient($smtp_server, $port);
- $smtp.EnableSSL = $true
- $smtp.Credentials = New-Object System.Net.NetworkCredential($username, $password);
- $smtp.send($message)
- Write-Host E-mail has been sent to $to
- Write-Host From: $username Server: $smtp_server Port: $port
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement