# Fix Veeam Backups Next Run, a Veeam PowerShell script (Version 1) # This script will properly set the Next Run schedule when entering a new day so that all jobs don't run between midnight and 1 am # A Windows Task Scheduler must be configured to run this script on each Veeam Backup Repository server -- running at 11:55 pm each evening # Run this on a Veeam Backup and Replication version 8 update 1 server # You could even copy and paste it into Veeam Backup and Replication > Menu > PowerShell # Written by Jason Pearce of www.jasonpearce.com in March 2015 # Use at your own risk, freely share, and comment on improvements # BEGIN Script ############################### # Enable Veeam PowerShell Snapin Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue # BEGIN variables ############################ # Get All, Some, or One backup jobs. # You MUST uncomment and modify one of these lines to target one or more backup jobs. # Only one line should begin with "$jobs =". These are just four helpful examples. #By-All# $jobs = Get-VBRJob | Where-Object { $_.IsBackup -eq $true -and $_.IsScheduleEnabled -eq $true } | Sort Name #By-PREFIX# $jobs = Get-VBRJob -Name "Test-*" | Where-Object { $_.IsBackup -eq $true -and $_.IsScheduleEnabled -eq $true } | Sort Name #By-LIST# $jobs = Get-VBRJob -Name "Test-1","Test-2" | Where-Object { $_.IsBackup -eq $true -and $_.IsScheduleEnabled -eq $true } | Sort Name #By-NAME# $jobs = Get-VBRJob -Name "Test-Job" | Where-Object { $_.IsBackup -eq $true -and $_.IsScheduleEnabled -eq $true } | Sort Name # END variables ############################## # BEGIN foreach loop ######################### # Make the following changes to all backup jobs foreach ($job in $jobs) { # BEGIN Job Schedule Options ############# # Get Current Job Schedule Options $currentJobScheduleOptions = Get-VBRJobScheduleOptions -Job $job # Create a new job schedule $newJobScheduleOptions = New-VBRJobScheduleOptions # Enable Periodically Schedule $newJobScheduleOptions.OptionsPeriodically.Enabled = $currentJobScheduleOptions.OptionsPeriodically.Enabled # Get Current Periodic Schedule Kind (0 = Hours, 1 = Minutes) $newJobScheduleOptions.OptionsPeriodically.Kind = $currentJobScheduleOptions.OptionsPeriodically.Kind # Get Current Other Schedules $newJobScheduleOptions.OptionsDaily.Enabled = $currentJobScheduleOptions.OptionsDaily.Enabled $newJobScheduleOptions.OptionsMonthly.Enabled = $currentJobScheduleOptions.OptionsMonthly.Enabled $newJobScheduleOptions.OptionsContinuous.Enabled = $currentJobScheduleOptions.OptionsContinuous.Enabled # Get Current FullPeriod offset $newJobScheduleOptions.OptionsPeriodically.FullPeriod = $currentJobScheduleOptions.OptionsPeriodically.FullPeriod # Get Current HourlyOffset $newJobScheduleOptions.OptionsPeriodically.HourlyOffset = $currentJobScheduleOptions.OptionsPeriodically.HourlyOffset # Get Current RetryTimeout $newJobScheduleOptions.RetryTimeout = $currentJobScheduleOptions.RetryTimeout # Do some math to calculate the desired NextRun value by adding FullPeriod to LastRun $newJobScheduleOptions.LatestRun = $currentJobScheduleOptions.LatestRun $newJobScheduleOptions.NextRun = ($currentJobScheduleOptions.LatestRun).AddMinutes($currentJobScheduleOptions.OptionsPeriodically.FullPeriod) # Apply the new job schedule Set-VBRJobScheduleOptions -Job $job -Options $newJobScheduleOptions # END Job Schedule Options ############### # Report which jobs received these changes Write-Host "Changed settings for" $job.Name } # END foreach loop ########################### # END script #################################