Was hoping someone could look it over and make sure it works as intended... one thing that is not working as intended is the secondary backup (to tape) jobs being copied across. Doing some research on that, and will implement it at some point. I have run it... once... it appeared to do what was intended. Since it appears to have worked on its first run, it is not debugged at all. Review and run with discretion.
Other than that, assuming someone points out a glaring omission, hopefully this will save others some time.
To use it, simply create a backup job, exactly as you want the rest to be. Yes, I could put these as variables at the start, but that's no fun.
You will need to edit:
1) The $vms variable near the beginning
2) The name of the template job to find and use as a template job, 3 lines down
3) Within the foreach loop, edit the naming scheme at the start (mine is simply B2D_<vm name>_PWS).
Code: Select all
#Edit this criteria to select the VMs you want.
$vms = Find-VBRViEntity | ?{$_.criteria -eq "Whatyouwantedtobackup"}
#Select a template job, set up manually via the wizard. It should be ready to rock and roll. You will need to edit the name of this job to be the same as what you've defined.
$templatejob = Get-VBRJob -name "B2D_Server01_PWS"
#Get the template job's job options.
$templateoptions = Get-VBRJobOptions $templatejob
#Get the template schedule
$templatesched = Get-VBRJobScheduleOptions $templatejob
#Iterate through each vm in $vms, as gathered by Find-VBRViEntity
foreach ($vm in $vms){
#Define the job name
$jobname = "B2D_$($vm.Name)_PWS"
#Write it to the shell for peace of mind
write-host $jobname
#Generate a backup job
Add-VBRViBackupJob -Name $jobname -BackupRepository (Get-VBRBackupRepository -name PWS*)-entity $vm
#Find our newly created job
$job = Get-VBRJob | ?{$_.name -eq $jobname}
#Add the job options to it
$job | set-VBRJobOptions -Options $templateoptions
#Add the job schedule to it
$job | Set-VBRJobScheduleOptions -Options $templatesched
#Enable the schedule
$job.EnableScheduler()
}