PowerShell script exchange
Post Reply
dvieceli
Lurker
Posts: 2
Liked: never
Joined: Mar 24, 2022 7:16 am
Full Name: Davide V.
Contact:

Edit retention policy for all backup jobs which name starts with specific text

Post by dvieceli »

Hi,
I want to do the same edit of the retention policy as I read in topic powershell-f26/change-retention-policy- ... 50494.html but only for jobs which name starts with specific text.

thanks
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Edit retention policy for all backup jobs which name starts with specific text

Post by david.domask »

Hi Davide, welcome to the forums.

Vladimir's post here should still work: post279504.html#p279504

I will change it slightly thought as there is no need for some of the old methods that were used there.

Code: Select all

$Jobs = Get-VBRJob | where {$_.Jobtype -eq "Backup" -and $_.Name -like "SomeText*"}
foreach ($Job in $Jobs){
		$Options = Get-VBRJobOptions -Job $Job
		$Options.BackupStorageOptions.RetainCycles = "N"
		Set-VBRJobOptions -Job $Job -Options $Options
}
Replace "SomeText" with your specific text, and replace N with the desired retention value. This is for Restore Points however, if you use Days, let us know as there are different properties to change under BackupStorageOptions.

For example, I have several jobs that start with vmware-, and if I wanted to update their retention, I'd do:

Code: Select all

$Jobs = Get-VBRJob | where {$_.Jobtype -eq "Backup" -and $_.Name -like "vmware-*"}
foreach ($Job in $Jobs){
		$Options = Get-VBRJobOptions -Job $Job
		$Options.BackupStorageOptions.RetainCycles = "64"
		Set-VBRJobOptions -Job $Job -Options $Options
}
David Domask | Product Management: Principal Analyst
dvieceli
Lurker
Posts: 2
Liked: never
Joined: Mar 24, 2022 7:16 am
Full Name: Davide V.
Contact:

Re: Edit retention policy for all backup jobs which name starts with specific text

Post by dvieceli »

Hi David, first of all many thanks for the quick reply, and yes, I would like to use number of Days rather than restore points in the retention policy.
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Edit retention policy for all backup jobs which name starts with specific text

Post by david.domask »

Hi Davide, you're very welcome :)

For Days, we simply need to change RetainCycles to RetainDaysToKeep

Code: Select all

$Jobs = Get-VBRJob | where {$_.Jobtype -eq "Backup" -and $_.Name -like "SomeText-*"}
foreach ($Job in $Jobs){
		$Options = Get-VBRJobOptions -Job $Job
		$Options.BackupStorageOptions.RetainDaysToKeep= "N"
		Set-VBRJobOptions -Job $Job -Options $Options
}
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest