PowerShell script exchange
Post Reply
jevao
Enthusiast
Posts: 29
Liked: 3 times
Joined: Oct 28, 2011 11:38 pm
Full Name: James Collison
Contact:

Add VM to Existing Backup Job VMs and Templates View

Post by jevao »

Hello, Trying to add a VM to a Backup Job, but would like the VMs Path to use the VMs and Templates view, instead of the Hosts and Clusters View.
Have not found the code to add or change a VMs Path in an already existing backup job to a VMs and Templates folder.

Using the Add-VBRviBackupJob I am able to add a VM using the VMs and Templates folder using the -Entity option.

Code: Select all

$allvms = Find-VBRViEntity -VMsAndTemplates
$CreateJobVM = $allvms | ? { $_.name -in $VM }
Add-VBRViBackupJob -Name $CreateJobName -BackupRepository $CreateJobRep -Entity $CreateJobVM
But once the Backup Job is Created,
the only cmdlet I have found to add another VM to this already created Backup Job is "Add-VBRJobObject".

I have not figured out how to add a VM using the "Add-VBRJobObject" cmdlet that uses the VMs and Templates view.

Is it possible?
Thanks
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Add VM to Existing Backup Job VMs and Templates View

Post by veremin » 1 person likes this post

You can use Add-VBRViJobObject commandlet in order to add object to existing job. The script should look like the following:

Code: Select all

$Job = Get-VBRJob -name "Name of your backup job"
$Entity = Find-VBRViEntity -VMsAndTemplates -name "Name of your VM or template"
Add-VBRViJobObject -Job $Job -Entities $Entity
Thanks.
jevao
Enthusiast
Posts: 29
Liked: 3 times
Joined: Oct 28, 2011 11:38 pm
Full Name: James Collison
Contact:

Re: Add VM to Existing Backup Job VMs and Templates View

Post by jevao »

That was exactly what I needed. Thanks.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Add VM to Existing Backup Job VMs and Templates View

Post by veremin »

You're welcome. Feel free to contact us, if any other help is needed. Thanks.
deibel
Lurker
Posts: 1
Liked: never
Joined: Mar 31, 2016 10:43 am
Contact:

Re: Add VM to Existing Backup Job VMs and Templates View

Post by deibel »

Hi,
what do i need to add if i wannt to add a VM to all my Backup Jobs?

regards
jansjone
Lurker
Posts: 1
Liked: never
Joined: Jun 09, 2016 2:03 pm
Full Name: Janssen Jones
Contact:

[MERGED]:Find-VBRHvEntity takes forever - is there a faster

Post by jansjone »

Whenever I add a VM to a backup job using Powershell, it takes many minutes to do so, because Find-VBRHvEntity takes so long. Is there any way to add a VM to a job via Powershell without using this cmdlet, or is there a way to somehow speed it up? Also, I often delete and recreate VMs using the same name, and when I do, Veeam backups will fail unless I drop and re-add the VM to my backup job. I have Powershell to drop and re-add the VM, but it requires using Find-VBRHvEntity, which takes over 4 minutes to return a single object.

Here's my simplified code:

Code: Select all

  $Cluster = 'MyTestCluster"
  $VM = 'MyTestVM'
  $VBRJob = Get-VBRJob -Name MyTestJob

  #### This line takes over 4 minutes to run, but I don't see another way to  get a $VBRVMEntity object than using Find-VBRHVEntity ####
  $VBRVMEntity = Get-VBRServer -name $Cluster | Find-VBRHvEntity -Name $VM
  Add-VBRHvJobObject -Job $VBRJob -Entities $VBRVMEntity
Thanks,
Janssen
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Add VM to Existing Backup Job VMs and Templates View

Post by veremin »

Does you original, not simplified code has a cycle by any chance? If so, you can create a hash table (as described here) to run the said query only once - this should speed up the process significantly. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests