Code: Select all
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
foreach($job in (Get-VBRJob | Sort Name)){
}
$JobName = Get-VBRJob | where {$_.Name -eq $JobName}
$EnableJobAdd = "True" #True/False
$RetrySpecifiedAdd = "True" #True/False
$RetryTimesAdd = "3"
$RetryTimeoutAdd = "15"
$schedulemode = "Daily" #Daily/Monthly/Periodically/Continuous
$OptionsDailyAddKind = "Everyday" #Everyday/SelectedDays/WeekDays
$OptionsDailyAddDays = "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday"
#create a random time#
$Hours = (16,17,18,19,20,21,22,23,'00','01','02','03','04') | Get-Random | Out-String
$Minutes = "{0:D2}" -f (Get-Random -Minimum 0 -Maximum 59) | Out-String
$Time = ($Hours+':'+$Minutes+':00').replace("`n","")
$OptionsDailyAddTime = $Time #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()
}
Code: Select all
PS C:\temp> .\scheduletest.ps1
Property 'RetrySpecified' cannot be found on this object; make sure it exists
and is settable.
At C:\temp\scheduletest.ps1:24 char:1
+ $JobnameObjectSchedule.RetrySpecified = $true
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'RetryTimes' cannot be found on this object; make sure it exists and
is settable.
At C:\temp\scheduletest.ps1:28 char:1
+ $JobnameObjectSchedule.RetryTimes = $RetryTimesAdd
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'RetryTimeout' cannot be found on this object; make sure it exists
and is settable.
At C:\temp\scheduletest.ps1:29 char:1
+ $JobnameObjectSchedule.RetryTimeout = $RetryTimeoutAdd
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Enabled' cannot be found on this object; make sure it exists and is
settable.
At C:\temp\scheduletest.ps1:43 char:1
+ $JobnameObjectSchedule.OptionsDaily.Enabled = $false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Enabled' cannot be found on this object; make sure it exists and is
settable.
At C:\temp\scheduletest.ps1:44 char:1
+ $JobnameObjectSchedule.OptionsMonthly.Enabled = $false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Enabled' cannot be found on this object; make sure it exists and is
settable.
At C:\temp\scheduletest.ps1:45 char:1
+ $JobnameObjectSchedule.OptionsPeriodically.Enabled = $true
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Enabled' cannot be found on this object; make sure it exists and is
settable.
At C:\temp\scheduletest.ps1:46 char:1
+ $JobnameObjectSchedule.OptionsContinuous.Enabled = $false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Kind' cannot be found on this object; make sure it exists and is
settable.
At C:\temp\scheduletest.ps1:57 char:1
+ $JobnameObjectSchedule.OptionsDaily.Kind = $OptionsDailyAddKind
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Days' cannot be found on this object; make sure it exists and is
settable.
At C:\temp\scheduletest.ps1:58 char:1
+ $JobnameObjectSchedule.OptionsDaily.Days = $OptionsDailyAddDays
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'Time' cannot be found on this object; make sure it exists and is
settable.
At C:\temp\scheduletest.ps1:59 char:1
+ $JobnameObjectSchedule.OptionsDaily.Time = $OptionsDailyAddTime
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'NextRun' cannot be found on this object; make sure it exists and is
settable.
At C:\temp\scheduletest.ps1:60 char:1
+ $JobnameObjectSchedule.NextRun = $OptionsDailyAddTime
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'StartDateTime' cannot be found on this object; make sure it exists
and is settable.
At C:\temp\scheduletest.ps1:61 char:1
+ $JobnameObjectSchedule.StartDateTime = $OptionsDailyAddTime
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Set-VBRJobScheduleOptions : Cannot validate argument on parameter 'Job'. The
argument is null or empty. Supply an argument that is not null or empty and
then try the command again.
At C:\temp\scheduletest.ps1:63 char:32
+ Set-VBRJobScheduleOptions -Job $JobnameObject -Options $JobnameObjectSchedule
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Set-VBRJobScheduleOptions], Pa
rameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.Po
werShell.Command.SetVBRJobScheduleOptions
Property 'RunManually' cannot be found on this object; make sure it exists and
is settable.
At C:\temp\scheduletest.ps1:69 char:1
+ $JobnameObject.options.JobOptions.RunManually = $false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\temp\scheduletest.ps1:70 char:1
+ $JobnameObject.EnableScheduler()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
PS C:\temp>