PowerShell script exchange
Post Reply
alex.nunley
Influencer
Posts: 19
Liked: never
Joined: Jan 18, 2013 3:36 pm
Full Name: Alex Nunley
Contact:

Bulk job modification

Post by alex.nunley »

I am trying to modify a bunch of settings, mostly related to scheduling, on all jobs in BR 6.5. I have the following code, scraped together. It fails, saying the setting either doesnt exist or is not settable. I am not sure what to do, and am tearing my hair out. Ideas? Better methodologies?

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()
}
And here is the error i'm seeting

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>
alex.nunley
Influencer
Posts: 19
Liked: never
Joined: Jan 18, 2013 3:36 pm
Full Name: Alex Nunley
Contact:

Re: Bulk job modification

Post by alex.nunley »

And to be clear, the settings are available, and settable, as they currently have content, such as .RetrySpecified.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Bulk job modification

Post by veremin » 1 person likes this post

Though I don’t have a console right in the moment, I’d definitely start investigating with the following line, as It doesn’t make any sense at all. :

Code: Select all

$JobName = Get-VBRJob  | where {$_.Name -eq $JobName}
According to your code, $Jobname variable hasn’t been specified up to that moment, and you’re literally trying to find a job which name coincides with an unspecified variable; there is no doubt that after this step $Jobname will have nothing as its content, or, most likely, something like zero value.

As a result you see errors regarding corresponding methods that cannot be found on this object (0/unspecified variable).

You can check it by simply putting $Jobname after the abovementioned line, and see what kind of value it has:

Code: Select all

$JobName = Get-VBRJob  | where {$_.Name -eq $JobName}
$JobName
Hope this helps.
Thanks.
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Bulk job modification

Post by Sethbartlett » 1 person likes this post

I agree, your $JobName just needs to be the name of the job, you already have $JobnameObject.

So Change to something like :

Code: Select all

$JobName = "MyJob"
the rest should work because $JobNameObject is referenced from $JobName
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
alex.nunley
Influencer
Posts: 19
Liked: never
Joined: Jan 18, 2013 3:36 pm
Full Name: Alex Nunley
Contact:

Re: Bulk job modification

Post by alex.nunley »

Thanks! that was definitely the bulk of it. ..

now i have to find some missing terminator...
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Bulk job modification

Post by Sethbartlett » 1 person likes this post

All I did was pretty up your code and fix your if/else stuff, it should have been using elseif instead. This will fix your broken terminator issue. Also your initial "Foreach" loop doesn't do anything.

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
$JobnameObjectSchedule.RetryTimes = $RetryTimesAdd  
$JobnameObjectSchedule.RetryTimeout = $RetryTimeoutAdd

If ($RetrySpecifiedAdd -eq "True")
{
	$JobnameObjectSchedule.RetrySpecified = $true
} 
Else
{
	$JobnameObjectSchedule.RetrySpecified = $false
}

If ($schedulemode -eq "Daily")
{
$JobnameObjectSchedule.OptionsDaily.Enabled = $true
$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
}
ElseIf($schedulemode -eq "Monthly")
{
	$JobnameObjectSchedule.OptionsDaily.Enabled = $false
	$JobnameObjectSchedule.OptionsMonthly.Enabled = $true
	$JobnameObjectSchedule.OptionsPeriodically.Enabled = $false
	$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} 
ElseIf($schedulemode -eq "Periodically")
{
	$JobnameObjectSchedule.OptionsDaily.Enabled = $false
	$JobnameObjectSchedule.OptionsMonthly.Enabled = $false
	$JobnameObjectSchedule.OptionsPeriodically.Enabled = $true
	$JobnameObjectSchedule.OptionsContinuous.Enabled = $false
} 
ElseIf($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()
}
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 9 guests