Andys scripting corner - List / Set Scheduling Options

PowerShell script exchange

Andys scripting corner - List / Set Scheduling Options

Veeam Logoby Andreas Neufert » Wed Apr 11, 2012 7:05 pm 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
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Andys scripting corner - List / Set Scheduling Options

Veeam Logoby Andreas Neufert » Wed Apr 11, 2012 10:27 pm

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
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Andys scripting corner - List / Set Scheduling Options

Veeam Logoby Andreas Neufert » Thu Apr 12, 2012 8:08 pm

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()
}
Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Andys scripting corner - List / Set Scheduling Options

Veeam Logoby arnike » Mon Apr 23, 2012 6:57 am

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.
arnike
Lurker
 
Posts: 1
Liked: never
Joined: Thu Mar 31, 2011 9:25 am
Full Name: Neek

Re: Andys scripting corner - List / Set Scheduling Options

Veeam Logoby ThomasMc » Mon Apr 23, 2012 9:03 pm

You could just schedule it via windows task manager very simple and effective
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Andys scripting corner - List / Set Scheduling Options

Veeam Logoby Andreas Neufert » Sun Apr 29, 2012 10:04 pm

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
Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Andys scripting corner - List / Set Scheduling Options

Veeam Logoby hagepat » Thu Jun 07, 2012 10:54 am

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,
hagepat
Veeam ProPartner
 
Posts: 15
Liked: never
Joined: Tue Aug 31, 2010 1:17 pm

Re: Andys scripting corner - List / Set Scheduling Options

Veeam Logoby Andreas Neufert » Mon Jun 11, 2012 2:55 pm

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
Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Andys scripting corner - List / Set Scheduling Options

Veeam Logoby hagepat » Fri Jun 15, 2012 3:05 pm

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,
hagepat
Veeam ProPartner
 
Posts: 15
Liked: never
Joined: Tue Aug 31, 2010 1:17 pm

Re: Andys scripting corner - List / Set Scheduling Options

Veeam Logoby mx_michael.preis » Tue Oct 09, 2012 1:13 pm

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?
mx_michael.preis
Novice
 
Posts: 7
Liked: never
Joined: Mon Jun 18, 2012 10:17 am
Full Name: Michael Preis


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 5 guests