PowerShell script exchange
Post Reply
Daniel2
Enthusiast
Posts: 45
Liked: 21 times
Joined: Nov 25, 2019 8:16 am
Full Name: Daniel
Contact:

Error with Set-VBRJobScriptOptions

Post by Daniel2 »

I'm following the example in that article https://helpcenter.veeam.com/docs/backu ... l?ver=95u4

Code: Select all

$job = Get-VBRJob -Name "Infrasrtucture Backup"
[Veeam.Backup.PowerShell.Infos.VBRComputerBackupJob]$ComputerBackupJob = $job
$script = $ComputerBackupJob.ScriptOptions
[Veeam.Backup.PowerShell.Infos.VBRJobScriptOptions]$JobScriptOptions = $script
Set-VBRJobScriptOptions -JobScriptOptions $script -Periodicity Days -Day Thursday
I get the following convert error:

Code: Select all

Der Wert "Veeam.Backup.Core.CBackupJob" kann nicht in den Typ "Veeam.Backup.PowerShell.Infos.VBRComputerBackupJob" konvertiert werden. Fehler: "Unable to convert job type 'Backup' to EP policy management type"
I need to configure post-job scripts on a number of scripts. How to solve this?
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Error with Set-VBRJobScriptOptions

Post by oleg.feoktistov »

Hi Daniel,

The code you see in the example concerns agent managed backup jobs.
So, the error you get appears when you apply the script on regular backup jobs, which are of type CBackupJob and hold distinct properties.

Try the following solution lest to depend on job type:

Code: Select all

$jobs = Get-VBRJob
foreach ($job in $jobs) {
$joboptions = $job.GetOptions()
$joboptions.JobScriptCommand.PreScriptEnabled = $true
$joboptions.JobScriptCommand.PreScriptCommandLine = 'C:\pre-job.ps1'
$joboptions.JobScriptCommand.PostScriptEnabled = $true
$joboptions.JobScriptCommand.PostScriptCommandLine = 'C:\post-job.ps1'
$joboptions.JobScriptCommand.Periodicity = 'Days'
$joboptions.JobScriptCommand.Frequency = 'Thursday'
Set-VBRJobOptions -job $job -Options $joboptions
}
Best regards,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests