PowerShell script exchange
Post Reply
unsichtbarre
Service Provider
Posts: 234
Liked: 40 times
Joined: Mar 08, 2010 4:05 pm
Full Name: John Borhek
Contact:

Looking to export all jobs with configs to CSV

Post by unsichtbarre »

Hi,
I would like to be able to export all jobs from a Veeam server with configs such as retention policy and RPO/schedule to a CSV.

I tried this: powershell-f26/export-to-csv-job-t62689.html

But it only exports the first job, and included none of the information I could use to document RPO policy and Retention policy. There has to be a better way than just screenshotting the job settings?
THX,
-JB
John Borhek, Solutions Architect
https://vmsources.com
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Looking to export all jobs with configs to CSV

Post by oleg.feoktistov » 2 people like this post

Hi John,

Sure, it involves diving a bit deeper into job options. Here is a small example with daily and monthly schedules:

Code: Select all

$jobs = Get-VBRJob
$summary = @()
foreach ($job in $jobs) {
  $scheduleKind = ''
  if ($job.ScheduleOptions.OptionsDaily.Enabled -eq $true) {
    $scheduleKind = 'Daily'
    $dailyKind = $job.ScheduleOptions.OptionsDaily.Kind
    $days = $job.ScheduleOptions.OptionsDaily.DaysSrv
  }

  elseif ($job.ScheduleOptions.OptionsMonthly.Enabled -eq $true) {
    $scheduleKind = 'Monthly'
    $monthIndex = $job.ScheduleOptions.OptionsMonthly.DayNumberInMonth
    $dayOfWeek = $job.ScheduleOptions.OptionsMonthly.DayOfWeek
    $months = $job.ScheduleOptions.OptionsMonthly.Months

  }
  if ($job.BackupStorageOptions.RetentionType -eq 'Cycles' -and $scheduleKind -eq 'Daily') {
  $summary += $job | select Name, @{n='RetentionType';e={$_.BackupStorageOptions.RetentionType}}, `
  @{n='RetainCycles';e={$_.BackupStorageOptions.RetainCycles}}, `
  @{n='ScheduleKind';e={$scheduleKind}}, @{n='DailyKind';e={$dailyKind}}, @{n='Days';e={$days}}
  }
  elseif ($Job.BackupStorageOptions.RetentionType -eq 'Days') {
  $summary += $job | select Name, @{n='RetentionType';e={$_.BackupStorageOptions.RetentionType}}, `
  @{n='RetainDays';e={$_.BackupStorageOptions.RetainDays}}, `
  @{n='ScheduleKind';e={$scheduleKind}}, @{n='MonthIndex';e={$monthIndex}}, @{n='DayOfWeek';e={$dayOfWeek}}, @{n='Months';e={$Months}}
  }
}

$summary | Export-Csv -Path 'C:\Summary.csv' 
I needed to show retention, retention type, schedule settings and reflect specific properties based on schedule type.

Hope you get the idea. If you have any questions, I'm here and glad to help.

Best regards,
Oleg
unsichtbarre
Service Provider
Posts: 234
Liked: 40 times
Joined: Mar 08, 2010 4:05 pm
Full Name: John Borhek
Contact:

Re: Looking to export all jobs with configs to CSV

Post by unsichtbarre »

So how do you add the VMs to the output?

THX,
-JB
John Borhek, Solutions Architect
https://vmsources.com
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Looking to export all jobs with configs to CSV

Post by oleg.feoktistov »

Easy.
Just insert this to foreach loop:

Code: Select all

$objects = Get-VBRJobObject -Job $job
And add object names to the summary:

Code: Select all

$summary += $job | select Name, @{n='VMs';e={$objects.Name} ...
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests