PowerShell script exchange
Post Reply
Dario.Palmisano
Enthusiast
Posts: 31
Liked: 2 times
Joined: Nov 11, 2013 7:22 am
Full Name: Dario Palmisano
Contact:

Is "EnableScheduler()" always available?

Post by Dario.Palmisano »

Hello,

I have a script to manage my backup jobs.

After the latest update to Veeam Backup and Replication (v. 9.5.0.1536), my scripts interrupts with error:

'Cannot find an overload for "EnableScheduler" and the argument count: "0".

I suppose when I run the following script fragment:

$Jobs[$JobSlot] = Get-VBRJob -Name $CopyJob

$JobName = $Jobs[$JobSlot].Name
$JobNameList += $JobName
LogMessage "Backup-Log" "Enabling: $JobName"
$Jobs[$JobSlot].EnableScheduler()

Is "EnableScheduler()" always available?

The fragment was perfectly working before the update!

Thanks
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Is "EnableScheduler()" always available?

Post by tsightler »

Note that the error message does not say the method isn't available, it says it could not find an overload for calling this method with "0" arguments. That's because, in 9.5 U3, most functions that modify a job now require an argument of type Veeam.Backup.Model.CModifiedUserInfo. Based on my testing you should be able to simply pass $null in most of these cases so EnableScheduler($null) should work.

That being said, when possible, it's probably best to use the available cmdlets rather than calling methods directly. The cmdlets are far less likely to have arbitrary changes like this so if your code looked something like the following instead, it would work the same with any recent version, including 9.5U3:

Code: Select all

$Jobs[$JobSlot] = Get-VBRJob -Name $CopyJob

$JobName = $Jobs[$JobSlot].Name
$JobNameList += $JobName
LogMessage "Backup-Log" "Enabling: $JobName"
Enable-VBRJobSchedule $Jobs[$JobSlot]
tdewin
Veeam Software
Posts: 1818
Liked: 655 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Is "EnableScheduler()" always available?

Post by tdewin »

Like Tom said, best to use the cmdlets instead of functions. Btw you can find the overload by just printing the functions without brackets e.g.:

Code: Select all

PS C:\Users\timothy> $d = get-date
PS C:\Users\timothy> $d.AddDays

OverloadDefinitions
-------------------
datetime AddDays(double value)
reaperhammer
Service Provider
Posts: 27
Liked: 9 times
Joined: Aug 18, 2016 7:59 pm
Full Name: Will S
Contact:

Re: Is "EnableScheduler()" always available?

Post by reaperhammer »

I have a similar issue, 9.5u3 requires aditional overloads for commands.

This script used to work now errors:

Code: Select all

$jobs = Get-VBRJob | where {$_.JobType -eq "Backup" -or $_.JobType -eq "Replica"}
foreach ($Job in $jobs){
$Options = $Job.GetOptions()
$Options.ViSourceOptions.DirtyBlocksNullingEnabled = $True
$Job.SetOptions($Options)
}
Cannot find an overload for "SetOptions" and the argument count: "1".
At line:4 char:1
+ $Job.SetOptions($Options)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest


It appears I need to create this object with type "Veeam.Backup.Model.CModifiedUserInfo" for the script to work now, how can I create an object with that type?

$job | gm | ?{$_.name -like "setoptions"} | fl *

TypeName : Veeam.Backup.Core.CBackupJob
Name : SetOptions
MemberType : Method
Definition : void SetOptions(Veeam.Backup.Model.CJobOptions jobOptions, Veeam.Backup.Model.CModifiedUserInfo initiator)
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Is "EnableScheduler()" always available?

Post by tsightler »

As stated above, probably best is to switch from calling method directly to using the appropriate cmdlet. The following command:

Code: Select all

$Job.SetOptions($Options)
Becomes:

Code: Select all

Set-VBRJobOptions -Job $Job -Options $Options
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests