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
-
- Novice
- Posts: 4
- Liked: 1 time
- Joined: Jun 27, 2018 1:03 pm
- Full Name: Paul MacDonald
- Contact:
-
- 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
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.
If you have any questions left, feel free to ask.
--au
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
}
--au
-
- 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
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.
Cheers,
Lucas H.
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
}}
Lucas H.
-
- 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
Thank you for your responses, I really appreciate the help.
This did exactly what I needed!
Code: Select all
$Jobs = Get-VBRJob
foreach($Job in $Jobs) {
$Options = $Job.GetOptions()
$Options.BackupStorageOptions.RetainCycles = '45'
Set-VBRJobOptions $Job $Options
}
Who is online
Users browsing this forum: No registered users and 8 guests