PowerShell script exchange
Post Reply
stanlion
Novice
Posts: 3
Liked: 1 time
Joined: Apr 27, 2022 9:48 am
Full Name: Stanley
Contact:

How can export those backup schedule include the datetime setting via powershell?

Post by stanlion » 1 person likes this post

Hi,

How can export those backup schedule detail include the datetime setting via powershell? Thanks.

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

Re: How can export those backup schedule include the datetime setting via powershell?

Post by oleg.feoktistov »

Hi Stanley and welcome to our R&D forums!

The approach would depend on the types of jobs you want to export schedule settings for.
Please let me know all the types needed (e.g. agents backup/backup copy, NAS, VMware, Hyper-V etc.)

Thanks,
Oleg
stanlion
Novice
Posts: 3
Liked: 1 time
Joined: Apr 27, 2022 9:48 am
Full Name: Stanley
Contact:

Re: How can export those backup schedule include the datetime setting via powershell?

Post by stanlion »

Hi Oleg,

Thanks for your reply, I would like to export the schedule setting for VMware Backup.

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

Re: How can export those backup schedule include the datetime setting via powershell?

Post by oleg.feoktistov » 2 people like this post

Adjusted the code I usually use, so something like that should do:

Code: Select all

$jobs = Get-VBRJob -WarningAction SilentlyContinue | where {$_.TypeToString -eq 'VMware Backup'}
$jobsScheduleDisabled = @()
$jobsScheduleDaily = @()
$jobsScheduleMonthly = @()
$jobsSchedulePeriodically = @()
$jobsScheduleContinuous = @()
$jobsScheduleAfterJob = @()

foreach ($job in $jobs) {
  if ($job.Options.JobOptions.RunManually -eq $true) {
    $scheduleEnabled = $false
    $jobsScheduleDisabled += $job | select Id, Name, @{n='ScheduleEnabled';e={$scheduleEnabled}}
  }
  elseif ($job.Options.JobOptions.RunManually -eq $false) {
  $scheduleEnabled = $true
  if ($job.ScheduleOptions.OptionsDaily.Enabled -eq $true) {
    $schedule = $job.ScheduleOptions.OptionsDaily
    $scheduleType = 'Daily'
    $jobsScheduleDaily += $job | select Id, Name, @{n='ScheduleEnabled';e={$scheduleEnabled}}, @{n='ScheduleType';e={$scheduleType}}, `
    @{n='DailyKind';e={$schedule.Kind}}, @{n='Days';e={$schedule.DaysSrv}}, @{n='TimeLocal';e={$schedule.TimeLocal.TimeOfDay.ToString()}}
  }
  elseif ($job.ScheduleOptions.OptionsPeriodically.Enabled -eq $true) {
    $schedule = $job.ScheduleOptions.OptionsPeriodically
    $scheduleType = 'Periodically'
    $jobsSchedulePeriodically += $job | select Id, Name, @{n='ScheduleEnabled';e={$scheduleEnabled}}, @{n='ScheduleType';e={$scheduleType}}, `
    @{n='PeriodicallyKind';e={$schedule.Kind}}, @{n='FullPeriod';e={$schedule.FullPeriod}}, @{n='Schedule';e={$schedule.Schedule}}, `
    @{n='HourlyOffsetMin';e={$schedule.HourlyOffset}}

  }
  elseif ($job.ScheduleOptions.OptionsMonthly.Enabled -eq $true) {
    $schedule = $job.ScheduleOptions.OptionsMonthly
    $scheduleType = 'Monthly'
    $jobsScheduleMonthly += $job | select Id, Name, @{n='ScheduleEnabled';e={$scheduleEnabled}}, @{n='ScheduleType';e={$scheduleType}}, `
    @{n='DayNumberInMonth';e={$schedule.DayNumberInMonth}}, @{n='DayOfWeek';e={$schedule.DayOfWeek}}, @{n='Months';e={$schedule.Months}}
  }
  elseif ($job.ScheduleOptions.OptionsContinuous.Enabled -eq $true) {
    $schedule = $job.ScheduleOptions.OptionsContinuous
    $scheduleType = 'Continuous'
    $jobsScheduleContinuous += $job | select Id, Name, @{n='ScheduleEnabled';e={$scheduleEnabled}}, @{n='ScheduleType';e={$scheduleType}}, `
    @{n='Schedule';e={$schedule.Schedule}}
  }
  elseif ($job.ScheduleOptions.OptionsScheduleAfterJob.IsEnabled -eq $true) {
    $previousJob = Get-VBRJob -WarningAction SilentlyContinue | where {$_.Id -eq $job.PreviousJobIdInScheduleChain.Guid}
    $schedule = $previousJob | select @{n='PreviousJobId';e={$_.Id}}, @{n='PreviousJobName';e={$_.Name}}
    $scheduleType = 'AfterJob'
    $jobsScheduleAfterJob += $job | select Id, Name, @{n='ScheduleEnabled';e={$scheduleEnabled}}, @{n='ScheduleType';e={$scheduleType}}, `
    @{n='PreviousJobName';e={$schedule.PreviousJobName}}
  }
  }
  
}

$jobsScheduleDisabled | fl
$jobsScheduleDaily | fl
$jobsScheduleMonthly | fl
$jobsSchedulePeriodically | fl
$jobsScheduleContinuous | fl 
$jobsScheduleAfterJob | fl
It sorts VMware backup jobs by schedule type and extracts the most relevant properties. Further on, you can use export cmdlets to present the data as csv, html etc.

Let me know if you need any further help.

Best regards,
Oleg
stanlion
Novice
Posts: 3
Liked: 1 time
Joined: Apr 27, 2022 9:48 am
Full Name: Stanley
Contact:

Re: How can export those backup schedule include the datetime setting via powershell?

Post by stanlion »

It's work, many thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests