PowerShell script exchange
Post Reply
macp2153
Novice
Posts: 4
Liked: 1 time
Joined: Jun 27, 2018 1:03 pm
Full Name: Paul MacDonald
Contact:

Powershell script to set restore point for 400 jobs

Post by macp2153 »

Hi I am very new to powershell and need a script to set the restore point to keep for 400 jobs. I searched the forums and found a few scripts that looked like what I needed but can get them to work. I am able to run the script and edit the restore points for one job by passing in the name but if I try and run it against all jobs I get an error

$Job = Get-VBRJob -name "TEST"
$Options = $Job.GetOptions()
$Options.BackupStorageOptions.RetainCycles = '45'
Set-VBRJobOptions $Job $Options

This works for the job TEST but if I remove the name parameter I get the following error:

$Job = Get-VBRJob
$Options = $Job.GetOptions()
$Options.BackupStorageOptions.RetainCycles = '45'
Set-VBRJobOptions $Job $Options

The property 'RetainCycles' cannot be found on this object. Verify that the property exists and can be set.
At C:\Temp\logs\Powershell\Powershell report\SET_BackupStorageOptions.RetainCycles_2.ps1:3 char:1
+ $Options.BackupStorageOptions.RetainCycles = '45'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException

Set-VBRJobOptions : Cannot convert 'System.Object[]' to the type 'Veeam.Backup.Model.CJobOptions' required by parameter 'Options'. Specified method is not supported.
At C:\Temp\logs\Powershell\Powershell report\SET_BackupStorageOptions.RetainCycles_2.ps1:4 char:24
+ Set-VBRJobOptions $Job $Options
+ ~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-VBRJobOptions], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Veeam.Backup.PowerShell.Cmdlets.SetVBRJobOptions

Thanks for any help with this
Alex Uryumtsev
Enthusiast
Posts: 51
Liked: 7 times
Joined: Oct 29, 2018 9:56 am
Full Name: Alexander Uryumtsev
Contact:

Re: Powershell script to set restore point for 400 jobs

Post by Alex Uryumtsev »

Hi Paul and welcome to the forum.

The cmdlet Get-VBRJob returns many objects. That's why your script in not working.

Here is the working script.

Code: Select all

$Jobs = Get-VBRJob
foreach($Job in $Jobs) {
    $Options = $Job.GetOptions()
    $Options.BackupStorageOptions.RetainCycles = '45'
    Set-VBRJobOptions $Job $Options
} 
If you have any questions left, feel free to ask.

--au
Lucas_H
Influencer
Posts: 17
Liked: 4 times
Joined: Nov 16, 2018 3:14 pm
Full Name: Lucas HELLMANN
Location: Lyon, FRANCE
Contact:

Re: Powershell script to set restore point for 400 jobs

Post by Lucas_H »

Hello,

To add to what Alex posted, I'm personnaly using a separate txt file where I just put the list of all the Job I want to modify, and then here is my code :
The first line of my txt file is JOBNAME, then I list all the job I want to modify line by line.

Code: Select all

Asnp VeeamPSSnapin
$Line = Import-Csv TEXT FILE WITH JOBNAME LISTED.txt
$Line | ForEach-Object {    
    $JobName = $_.JOBNAME #The first line of your .txt file must be JOBNAME
    $Jobs = Get-VBRJob -Name $JobName
    foreach ($Job in $Jobs) {
        $Options = $Job.GetOptions()
        $Options.Backupstorageoptions.retaincycles = 15 #Change value here
        Set-VBRJobOptions -Job $Job -Options $Options
    }}
Cheers,
Lucas H.
macp2153
Novice
Posts: 4
Liked: 1 time
Joined: Jun 27, 2018 1:03 pm
Full Name: Paul MacDonald
Contact:

Re: Powershell script to set restore point for 400 jobs

Post by macp2153 » 1 person likes this post

Thank you for your responses, I really appreciate the help.

Code: Select all

$Jobs = Get-VBRJob
foreach($Job in $Jobs) {
    $Options = $Job.GetOptions()
    $Options.BackupStorageOptions.RetainCycles = '45'
    Set-VBRJobOptions $Job $Options
} 
This did exactly what I needed!
Post Reply

Who is online

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