I just wanted to share my latest PowerShell script creation.
The script does the following:
-Fetches all jobs created in Veeam.
-Goes through them, selecting only Backup jobs
-Executes each found backup job
-Saves status for the job
-generates an email with status for all the jobs, and a total status (if just one job failed the total status will show failed).
-Sends the email.
Here's the script (all comments written in Danish, but I hope you'll be able to understand anyway)
Code: Select all
############################################################
# PowerShell script til backup af VM
#
############################################################
# indlæs Veeam kommando-plugin
Add-PSSnapin VeeamPSSnapIn
# samlet status initieres med "Success" - ændres kun hvis en eller flere backups fejler
$statustot = "Success"
# variabel for opsamling af backup status til email
$statussamlet
# hent info om alle jobs i Veeam
$jobs = Get-VBRJob
# tæller for loop
$i = 0
do{
# udføres kun hvis jobtype er 'Backup'
if ($jobs[$i].jobtargettype -eq "Backup"){
$name = $jobs[$i].name
# tag backup af VM
Get-VBRJob | where {$_.Name –eq $name} | Start-VBRJob
# hent status for backup job
$status = (Get-VBRJob | where {$_.Name -eq $name}).info.lateststatus
# opdater samlet status
if ($status -ne "Success"){
$statustot = "Fejl"
}
$statussamlet = "$statussamlet Status for '$name' : $status `n"
}
$i++
}
while($i -le $jobs.length-1)
# klargør besked til email
$statussamlet = "$statussamlet `n Samlet status: $statustot"
$emailbody = "Status for Veeam backup af VMware virtuelle maskiner: `n`n$statussamlet"
# send email med samlet status for alle jobs
$SMTPserver = "smtp.my-mailserver.com"
$from = "VeeamBackupScript@my-domain.com"
$to = "backup-list@my-domain.com"
$subject = "Veeam backup script status: $statustot"
$mailer = new-object Net.Mail.SMTPclient($SMTPserver)
$msg = new-object Net.Mail.MailMessage($from, $to, $subject, $emailbody)
$mailer.send($msg)