PowerShell script exchange
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Powershell to list Backup Job name, VMs and its retention?

Post by oleg.feoktistov »

As for GFS retention, I've just thrown together a PS function, which would display GFS retention of a job in cmdlet-like way:

Code: Select all

function Get-VBRGFSRetentionPolicy {
 [CmdletBinding()]
 param (
  [Veeam.Backup.Core.CBackupJob[]]$Job
 )

 foreach ($item in $Job) {
  if ($item.Options.GfsPolicy.IsEnabled -eq $true) {
   $GFS = 'Enabled'
  }

  else {
   $GFS = 'Disabled'
  }

  if ($item.Options.GFSPolicy.Weekly.IsEnabled -eq $true) {
   $WeeklyRetention = 'Enabled'
  }

  else {
   $WeeklyRetention = 'Disabled'
  }

  if ($item.Options.GFSPolicy.Monthly.IsEnabled -eq $true) {
   $MonthlyRetention = 'Enabled'
  }

  else {
   $MonthlyRetention = 'Disabled'
  }

  if ($item.Options.GFSPolicy.Yearly.IsEnabled -eq $true) {
   $YearlyRetention = 'Enabled'
  }

  else {
   $YearlyRetention = 'Disabled'
  }

  if ($WeeklyRetention -eq 'Enabled' -and $MonthlyRetention -eq 'Enabled' -and $YearlyRetention -eq 'Enabled') {
   $item | select Name, @{n='Type';e={$_.TypeToString}}, @{n='State';e={$_.GetLastState()}}, `
   @{n='GFS Policy';e={$GFS}}, @{n='WeeklyRetention';e={"$($_.Options.GFSPolicy.Weekly.KeepBackupsForNumberOfWeeks) Week(s)"}}, `
   @{n='WeeklyDesiredTime';e={$_.Options.GFSPolicy.Weekly.DesiredTime}}, `
   @{n='MonthlyRetention';e={"$($_.Options.GFSPolicy.Monthly.KeepBackupsForNumberOfMonths) Month(s)"}}, `
   @{n='MonthlyDesiredTime';e={$_.Options.GFSPolicy.Monthly.DesiredTime}}, `
   @{n='YearlyRetention';e={"$($_.Options.GFSPolicy.Yearly.KeepBackupsForNumberOfYears) Year(s)"}}, `
   @{n='YearlyDesiredTime';e={$_.Options.GFSPolicy.Yearly.DesiredTime}}
  }

  elseif ($WeeklyRetention -eq 'Enabled' -and $MonthlyRetention -eq 'Enabled' -and $YearlyRetention -eq 'Disabled') {
   $item | select Name, @{n='Type';e={$_.TypeToString}}, @{n='State';e={$_.GetLastState()}}, `
   @{n='GFS Policy';e={$GFS}}, @{n='WeeklyRetention';e={"$($_.Options.GFSPolicy.Weekly.KeepBackupsForNumberOfWeeks) Week(s)"}}, `
   @{n='WeeklyDesiredTime';e={$_.Options.GFSPolicy.Weekly.DesiredTime}}, `
   @{n='MonthlyRetention';e={"$($_.Options.GFSPolicy.Monthly.KeepBackupsForNumberOfMonths) Month(s)"}}, `
   @{n='MonthlyDesiredTime';e={$_.Options.GFSPolicy.Monthly.DesiredTime}}, `
   @{n='YearlyRetention';e={""}}, `
   @{n='YearlyDesiredTime';e={""}}
   }

  elseif ($WeeklyRetention -eq 'Enabled' -and $MonthlyRetention -eq 'Disabled' -and $YearlyRetention -eq 'Disabled') {
   $item | select Name, @{n='Type';e={$_.TypeToString}}, @{n='State';e={$_.GetLastState()}}, `
   @{n='GFS Policy';e={$GFS}}, @{n='WeeklyRetention';e={"$($_.Options.GFSPolicy.Weekly.KeepBackupsForNumberOfWeeks) Week(s)"}}, `
   @{n='WeeklyDesiredTime';e={$_.Options.GFSPolicy.Weekly.DesiredTime}}, `
   @{n='MonthlyRetention';e={""}}, `
   @{n='MonthlyDesiredTime';e={""}}, `
   @{n='YearlyRetention';e={""}}, `
   @{n='YearlyDesiredTime';e={""}}
   }

  elseif ($WeeklyRetention -eq 'Enabled' -and $MonthlyRetention -eq 'Disabled' -and $YearlyRetention -eq 'Enabled') {
   $item | select Name, @{n='Type';e={$_.TypeToString}}, @{n='State';e={$_.GetLastState()}}, `
   @{n='GFS Policy';e={$GFS}}, @{n='WeeklyRetention';e={"$($_.Options.GFSPolicy.Weekly.KeepBackupsForNumberOfWeeks) Week(s)"}}, `
   @{n='WeeklyDesiredTime';e={$_.Options.GFSPolicy.Weekly.DesiredTime}}, `
   @{n='MonthlyRetention';e={""}}, `
   @{n='MonthlyDesiredTime';e={""}}, `
   @{n='YearlyRetention';e={"$($_.Options.GFSPolicy.Yearly.KeepBackupsForNumberOfYears) Year(s)"}}, `
   @{n='YearlyDesiredTime';e={$_.Options.GFSPolicy.Yearly.DesiredTime}}
   }

  elseif ($WeeklyRetention -eq 'Disabled' -and $MonthlyRetention -eq 'Enabled' -and $YearlyRetention -eq 'Enabled') {
   $item | select Name, @{n='Type';e={$_.TypeToString}}, @{n='State';e={$_.GetLastState()}}, `
   @{n='GFS Policy';e={$GFS}}, @{n='WeeklyRetention';e={""}}, `
   @{n='WeeklyDesiredTime';e={""}}, `
   @{n='MonthlyRetention';e={"$($_.Options.GFSPolicy.Monthly.KeepBackupsForNumberOfMonths) Month(s)"}}, `
   @{n='MonthlyDesiredTime';e={$_.Options.GFSPolicy.Monthly.DesiredTime}}, `
   @{n='YearlyRetention';e={"$($_.Options.GFSPolicy.Yearly.KeepBackupsForNumberOfYears) Year(s)"}}, `
   @{n='YearlyDesiredTime';e={$_.Options.GFSPolicy.Yearly.DesiredTime}}
}

  elseif ($WeeklyRetention -eq 'Disabled' -and $MonthlyRetention -eq 'Enabled' -and $YearlyRetention -eq 'Disabled') {
   $item | select Name, @{n='Type';e={$_.TypeToString}}, @{n='State';e={$_.GetLastState()}}, `
   @{n='GFS Policy';e={$GFS}}, @{n='WeeklyRetention';e={""}}, `
   @{n='WeeklyDesiredTime';e={""}}, `
   @{n='MonthlyRetention';e={"$($_.Options.GFSPolicy.Monthly.KeepBackupsForNumberOfMonths) Month(s)"}}, `
   @{n='MonthlyDesiredTime';e={$_.Options.GFSPolicy.Monthly.DesiredTime}}, `
   @{n='YearlyRetention';e={""}}, `
   @{n='YearlyDesiredTime';e={""}}
   }

  elseif ($WeeklyRetention -eq 'Disabled' -and $MonthlyRetention -eq 'Disabled' -and $YearlyRetention -eq 'Enabled') {
   $item | select Name, @{n='Type';e={$_.TypeToString}}, @{n='State';e={$_.GetLastState()}}, `
   @{n='GFS Policy';e={$GFS}}, @{n='WeeklyRetention';e={""}}, `
   @{n='WeeklyDesiredTime';e={""}}, `
   @{n='MonthlyRetention';e={""}}, `
   @{n='MonthlyDesiredTime';e={""}}, `
   @{n='YearlyRetention';e={$_.Options.GFSPolicy.Yearly.KeepBackupsForNumberOfYears}}, `
   @{n='YearlyDesiredTime';e={$_.Options.GFSPolicy.Yearly.DesiredTime}}
  }

  else {
   $item | select Name, @{n='Type';e={$_.TypeToString}}, @{n='State';e={$_.GetLastState()}}, `
   @{n='GFS Policy';e={$GFS}}, @{n='WeeklyRetention';e={""}}, `
   @{n='WeeklyDesiredTime';e={""}}, `
   @{n='MonthlyRetention';e={""}}, `
   @{n='MonthlyDesiredTime';e={""}}, `
   @{n='YearlyRetention';e={""}}, `
   @{n='YearlyDesiredTime';e={""}}
  }
 }
}
The syntax is:

Code: Select all

$job = Get-VBRJob
$retention = Get-VBRGFSRetentionPolicy -Job $job
Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests