PowerShell script exchange
Post Reply
Andreas Neufert
VP, Product Management
Posts: 4586
Liked: 874 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Andys scripting corner - List / Set Scheduling Options

Post by Andreas Neufert » 1 person likes this post

This was a hard one, because there are some wrong displayed options and you need additional commands.

Code: Display Job scheduling options:

Code: Select all


Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
$JobName = "Rep001-002-auto-Win2008-XX"
$JobnameObject = Get-VBRJob | Where {$_.Name -eq $JobName}
$JobnameObjectSchedule = $JobnameObject | Get-VBRjobscheduleoptions
$JobnameObjectSchedule
write-host "--------------------------------------------------------------------------------------------"
write-host "OptionsDaily"
$JobnameObjectSchedule.OptionsDaily
write-host "--------------------------------------------------------------------------------------------"
write-host "OptionsMonthly"
$JobnameObjectSchedule.OptionsMonthly
write-host "--------------------------------------------------------------------------------------------"
write-host "OptionsPeriodically"
$JobnameObjectSchedule.OptionsPeriodically
write-host "--------------------------------------------------------------------------------------------"
write-host "OptionsContinuous"
$JobnameObjectSchedule.OptionsContinuous
write-host "--------------------------------------------------------------------------------------------"
write-host "OptionsBackupWindow"
$JobnameObjectSchedule.OptionsBackupWindow

Write-host "Be carefull, OptionsDaily displays optionsdaily.kind as DayNumberInMonth"


Example output:

Code: Select all

PS E:\scripts> E:\scripts\settings\scheduleOptions.ps1


StartDateTime                     : 11.04.2012 20:00:00
EndDateTimeSpecified              : False
EndDateTime                       : 13.04.2012 21:00:06
RepeatSpecified                   : False
RepeatNumber                      : 1
RepeatTimeUnit                    : hour(s)
RepeatTimeUnitMs                  : 3600000
RetryTimes                        : 2
RetryTimeout                      : 22
RetrySpecified                    : True
WaitForBackupCompletion           : True
BackupCompetitionWaitingPeriodMin : 180
OptionsDaily                      : Enabled: True, DayNumberInMonth: SelectedDays, Days: Monday, Tuesday, Wednesday, Thursday, Friday
OptionsMonthly                    : Enabled: False, Time: 11.04.2012 00:00:00, Day Number In Month: Second, Day Of Week: Monday, Months: January, February, March, April, May, June, July, August, September, October, 
                                    November, December
OptionsPeriodically               : Enabled: False, Period: 1 hour(s), ScheduleString: <scheduler><Sunday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Sunday><Monday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                                    ,0</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Tuesday><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Wednesday><Thursday>0,0,0,0,0,0,0,0,0,0,0,
                                    0,0,0,0,0,0,0,0,0,0,0,0,0</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Friday><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Saturday></scheduler
                                    >
OptionsContinuous                 : Enabled: False
OptionsBackupWindow               : Veeam.Backup.Model.CBackupWindowOptions
NextRun                           : 04/12/2012 20:00:00
LatestRun                         : 11.04.2012 20:16:00

--------------------------------------------------------------------------------------------
OptionsDaily
Enabled : True
Kind    : SelectedDays
Days    : {Monday, Tuesday, Wednesday, Thursday...}
Time    : 11.04.2012 21:00:00

--------------------------------------------------------------------------------------------
OptionsMonthly
Enabled          : False
Time             : 11.04.2012 00:00:00
DayNumberInMonth : Second
DayOfWeek        : Monday
Months           : {January, February, March, April...}

--------------------------------------------------------------------------------------------
OptionsPeriodically
Enabled    : False
Kind       : Hours
FullPeriod : 60
Schedule   : <scheduler><Sunday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Sunday><Monday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Tuesd
             ay><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Wednesday><Thursday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Frid
             ay><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Saturday></scheduler>

--------------------------------------------------------------------------------------------
OptionsContinuous
Enabled : False

--------------------------------------------------------------------------------------------
OptionsBackupWindow
IsEnabled    : False
BackupWindow : <scheduler><Sunday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Sunday><Monday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Tue
               sday><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Wednesday><Thursday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</
               Friday><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Saturday></scheduler>

Be carefull, OptionsDaily displays optionsdaily.kind as DayNumberInMonth

Example Set-VBRJobScheduleOptions

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

$JobName = "Rep001-002-auto-Win2008-XX"

$EnableJobAdd = "True" #True/False
$RetrySpecifiedAdd = "True" #True/False
$RetryTimesAdd = "2"
$RetryTimeoutAdd = "22"
$schedulemode = "Daily" #Daily/Monthly/Periodically/Continuous
$OptionsDailyAddKind = "SelectedDays" #Everyday/SelectedDays/WeekDays
$OptionsDailyAddDays = "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday"
$OptionsDailyAddTime = "21:00:00" #Attention: If you set a new time. The "Next run" column in the jobview will be updated after the next job run.

$JobnameObject = Get-VBRJob | Where {$_.Name -eq $JobName}
$JobnameObjectSchedule = $JobnameObject | Get-VBRjobscheduleoptions
If ($RetrySpecifiedAdd -eq "True"){
$JobnameObjectSchedule.RetrySpecified = $true
} ELSE {
$JobnameObjectSchedule.RetrySpecified = $false
}
$JobnameObjectSchedule.RetryTimes = $RetryTimesAdd  
$JobnameObjectSchedule.RetryTimeout = $RetryTimeoutAdd
If ($schedulemode -eq "Daily"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $true
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Monthly"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $true
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Periodically"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $true
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Continuous"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $true
} ELSE {
write-host "Error: Schedulemode entry not correct"
}}}}

$JobnameObjectSchedule.OptionsDaily.Kind = $OptionsDailyAddKind
$JobnameObjectSchedule.OptionsDaily.Days = $OptionsDailyAddDays
$JobnameObjectSchedule.OptionsDaily.Time = $OptionsDailyAddTime
Set-VBRJobScheduleOptions -Job $JobnameObject -Options $JobnameObjectSchedule



If ($EnableJobAdd -eq "True"){
$JobnameObject.options.JobOptions.RunManually = $false
$JobnameObject.EnableScheduler()
} ELSE {
$JobnameObject.options.JobOptions.RunManually = $true
$JobnameObject.DisableScheduler()
}

Andreas Neufert
VP, Product Management
Posts: 4586
Liked: 874 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Andys scripting corner - List / Set Scheduling Options

Post by Andreas Neufert »

Hi ... I have to say sorry, but the code not working on one point.

Code: Select all

$OptionsDailyAddTime = "21:00:00"
$JobnameObjectSchedule.OptionsDaily.Time = $OptionsDailyAddTime
Set-VBRJobScheduleOptions -Job $JobnameObject -Options $JobnameObjectSchedule
works only for some seconds. After that B&R automatically set jobcreation time +5 minutes. For next run.

Same problem like here

I will check this out internally.

Andreas Neufert
VP, Product Management
Posts: 4586
Liked: 874 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Andys scripting corner - List / Set Scheduling Options

Post by Andreas Neufert »

This one works.
You have to set more options in Version 6 for dailyjob time.

Example: Set scheduling time for daily backup scheduler

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

$JobName = "Rep001-002-auto-Win2008-XX"

$EnableJobAdd = "True" #True/False
$RetrySpecifiedAdd = "True" #True/False
$RetryTimesAdd = "2"
$RetryTimeoutAdd = "22"
$schedulemode = "Daily" #Daily/Monthly/Periodically/Continuous
$OptionsDailyAddKind = "SelectedDays" #Everyday/SelectedDays/WeekDays
$OptionsDailyAddDays = "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday"
$OptionsDailyAddTime = "23:02:00" #Attention: If you set a new time. The "Next run" column in the jobview will be updated after the next job run.

$JobnameObject = Get-VBRJob | Where {$_.Name -eq $JobName}
$JobnameObjectSchedule = $JobnameObject | Get-VBRjobscheduleoptions
If ($RetrySpecifiedAdd -eq "True"){
$JobnameObjectSchedule.RetrySpecified = $true
} ELSE {
$JobnameObjectSchedule.RetrySpecified = $false
}
$JobnameObjectSchedule.RetryTimes = $RetryTimesAdd  
$JobnameObjectSchedule.RetryTimeout = $RetryTimeoutAdd
If ($schedulemode -eq "Daily"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $true
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Monthly"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $true
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Periodically"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $true
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Continuous"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $true
} ELSE {
write-host "Error: Schedulemode entry not correct"
}}}}

$JobnameObjectSchedule.OptionsDaily.Kind = $OptionsDailyAddKind
$JobnameObjectSchedule.OptionsDaily.Days = $OptionsDailyAddDays
$JobnameObjectSchedule.OptionsDaily.Time = $OptionsDailyAddTime
$JobnameObjectSchedule.NextRun = $OptionsDailyAddTime
$JobnameObjectSchedule.StartDateTime = $OptionsDailyAddTime

Set-VBRJobScheduleOptions -Job $JobnameObject -Options $JobnameObjectSchedule


$JobnameObject = Get-VBRJob | Where {$_.Name -eq $JobName}

If ($EnableJobAdd -eq "True"){
$JobnameObject.options.JobOptions.RunManually = $false
$JobnameObject.EnableScheduler()
} ELSE {
$JobnameObject.options.JobOptions.RunManually = $true
$JobnameObject.DisableScheduler()
}

arnike
Lurker
Posts: 1
Liked: never
Joined: Mar 31, 2011 9:25 am
Full Name: Neek
Contact:

Re: Andys scripting corner - List / Set Scheduling Options

Post by arnike »

The script might work for daily jobs, but regarding periodical schedules I can't confirm it helps much.

Is it possible to set up a schedule to run a job once in 2 weeks? I already tried periodical schedule with 336 hours interval but sooner or later it resets to a once-in-a-week scheme. In v5 I used to fix it with the following script. To my disappointment it doesn't work for v6.


Let's suppose I want "BACKUP-ESX1" to run on 04.05.2012 21:00:00 and currently its next run time is 27.04.2012. After running

$NextRun = get-date ("04.05.2012 21:00:00")
$LastRun = $NextRun.AddDays(-14)

$Job = get-vbrjob | where {$_.name -eq "BACKUP-ESX1"}
$schedule = $job.GetScheduleOptions()
$schedule.NextRun = $NextRun
$schedule.LatestRun = $LastRun
Set-VBRJobScheduleOptions -job ($job) -options ($schedule)

Veeam console shows the change for a short time but then falls back on 27.04.2012.

ThomasMc
Expert
Posts: 293
Liked: 18 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Andys scripting corner - List / Set Scheduling Options

Post by ThomasMc »

You could just schedule it via windows task manager very simple and effective

Andreas Neufert
VP, Product Management
Posts: 4586
Liked: 874 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Andys scripting corner - List / Set Scheduling Options

Post by Andreas Neufert »

Hi arnike,

yes, in v6 there are some changes.
You need to set the time 3 times. in the scheduler, at next run and startdatetime.

Ad this to your script and I bet that this will work in v6 again.
If you look at my first post and second reply I had the exact same problem and you can see the changes in the code.

CU Andy

hagepat
Veeam ProPartner
Posts: 15
Liked: never
Joined: Aug 31, 2010 1:17 pm
Contact:

Re: Andys scripting corner - List / Set Scheduling Options

Post by hagepat »

Hi Andreas,

I'm sorry I don't understand. I used your script in v6. I set time at 2pm, periodically every 2 hours.
In the "next run" the time will change to 2pm but every 5 seconds in switches back to 2 hours from the job modification time.
You mentioned something about set the time 3 times. But where do I have to set the time 3 times do you have an solution for me.

Kind regards,

Andreas Neufert
VP, Product Management
Posts: 4586
Liked: 874 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

Re: Andys scripting corner - List / Set Scheduling Options

Post by Andreas Neufert »

Hi

I think this one works for preiodically backup:

Code: Select all

 
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

$JobName = "Fileserver4"

$EnableJobAdd = "True" #True/False
$RetrySpecifiedAdd = "True" #True/False
$RetryTimesAdd = "2"
$RetryTimeoutAdd = "22"

$schedulemode = "Periodically" #Daily/Monthly/Periodically/Continuous
$OptionsPeriFullPeriod = "120"
$OptionsPeriStarttime = "22:00" 

# ======================================================================
# Code 
#======================================================================

$JobnameObject = Get-VBRJob | Where {$_.Name -eq $JobName}
$JobnameObjectSchedule = $JobnameObject | Get-VBRjobscheduleoptions
If ($RetrySpecifiedAdd -eq "True"){
$JobnameObjectSchedule.RetrySpecified = $true
} ELSE {
$JobnameObjectSchedule.RetrySpecified = $false
}
$JobnameObjectSchedule.RetryTimes = $RetryTimesAdd  
$JobnameObjectSchedule.RetryTimeout = $RetryTimeoutAdd
If ($schedulemode -eq "Daily"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $true
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Monthly"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $true
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Periodically"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $true
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} ELSE {
If ($schedulemode -eq "Continuous"){
$JobnameObjectSchedule.OptionsDaily.Enabled = $false
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $true
} ELSE {
write-host "Error: Schedulemode entry not correct"
}}}}



$JobnameObjectSchedule.OptionsPeriodically = $OptionsPeriFullPeriod.number
$JobnameObjectSchedule.NextRun = $OptionsPeriStarttime
$JobnameObjectSchedule.StartDateTime = $OptionsPeriStarttime

Set-VBRJobScheduleOptions -Job $JobnameObject -Options $JobnameObjectSchedule


$JobnameObject = Get-VBRJob | Where {$_.Name -eq $JobName}

If ($EnableJobAdd -eq "True"){
$JobnameObject.options.JobOptions.RunManually = $false
$JobnameObject.EnableScheduler()
} ELSE {
$JobnameObject.options.JobOptions.RunManually = $true
$JobnameObject.DisableScheduler()
}
CU Andy

hagepat
Veeam ProPartner
Posts: 15
Liked: never
Joined: Aug 31, 2010 1:17 pm
Contact:

Re: Andys scripting corner - List / Set Scheduling Options

Post by hagepat »

Hi ANdy,

Script does not work. There is no option "daily, monthly, periodically or continious" selected after is run the script.
So time is 4:00pm daily but not selected. If job is run, it will never run again.

Unfortunatly

Maybe you have an other idea.

KInd regards,

mx_michael.preis
Novice
Posts: 7
Liked: never
Joined: Jun 18, 2012 10:17 am
Full Name: Michael Preis
Contact:

Re: Andys scripting corner - List / Set Scheduling Options

Post by mx_michael.preis »

We also have the same problem. We tried to edit your script, but it is not possible to alter the periodical options. Maybe there is a problem with the database, where the "schedule" column in the table "BJobs" is read-only.

Can you check this again?

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests