PowerShell script exchange
Post Reply
Kazz
Expert
Posts: 140
Liked: 17 times
Joined: Feb 08, 2018 3:47 am
Full Name: Kazz Beck
Contact:

move vms with exclusions script

Post by Kazz »

Hi,

I have a backup Job A with 12 VMs in it, I also have a Job B with 37 vms in it and some VMs (around 10) in job b have disk exclusions configured.
Is there a way to move vms from Job B to Job A with a power shell script and retain all exclusions as they are?

The final goal is to consolidate A and B in to just one Job A

Thank you
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: move vms with exclusions script

Post by oleg.feoktistov » 2 people like this post

Hi,

Yes, you would need to add VMs as new job objects to a target job and then update each of them with the exclusion data from the source job. An example for vSphere backup jobs:

Code: Select all

$targetJob = Get-VBRJob -Name 'Backup Job 1'
$sourceJob = Get-VBRJob -Name 'Backup Job 2'
$objects = Get-VBRJobObject -Job $sourceJob
foreach ($object in $objects) {
  $entity = Find-VBRViEntity -Name $object.Name -Server vsphere.local | where {$_.Reference -eq $object.Object.ObjectRef}
  Add-VBRViJobObject -Job $targetJob -Entities $entity
  $targetJob = Get-VBRJob -Name 'Backup Job 1'
  $targetObject = Get-VBRJobObject -Job $targetJob -Name $object.Name | where {$_.Object.ObjectRef -eq $object.Object.ObjectRef}
  $targetObject.Update($object.VssOptions, $object.DiskFilterInfo, $object.UpdateConfig, $object.Type)
}

This script will loop through each of objects of a source job you want to move the vms from, add and then update each of them in the target job separately. I'm using a conjunction of object name and vm reference on the vSphere infrastructure to filter each vm to avoid dealing with duplicated names.

Let me know if it helps,
Oleg
Kazz
Expert
Posts: 140
Liked: 17 times
Joined: Feb 08, 2018 3:47 am
Full Name: Kazz Beck
Contact:

Re: move vms with exclusions script

Post by Kazz »

Thanks Oleg!

I was able to scrip the move of the VMs but without the exclusions. This is super helpful, thanks again!
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests