Build Jobs Based on vSphere Tags

PowerShell script exchange

Build Jobs Based on vSphere Tags

Veeam Logoby swendel » Thu Apr 24, 2014 9:19 pm

(Veeam Backup 7)

I'm trying to automatically build jobs based on vSphere tags. So far, I can build the job using the following PowerCLI and Veeam PSS combo:

$backupobjects = Get-VM -Tag Level1
Add-VBRViBackupJob -Name <JobName> -BackupRepository <Repository> -Entity (Find-VBRViEntity -Name $backupobjects)

This builds the job with every VM that has the tag "Level1"

What I haven't been able to figure out is the code to remove/exclude (removing would be better) the VMs from the job at a later time. This would be so you can "repopulate" the job, removing any VMs that no longer have the tag, but preserving using the same VBK.

I tried a similar combo:

$oldbackupobjects = Get-VBRJobObject -Job <JobName> | fl "Name"
Get-VBRJob -Name <JobName> | Get-VBRJobObject -Name $oldbackupobjects | Remove-VBRJobObject

This doesn't give an error, but it doesn't do anything either.

If I do:

Get-VBRJob -Name <JobName> | Get-VBRJobObject -<VMName> | Remove-VBRJobObject

it will exclude the VM from the job.

Any help would be appreciated.
swendel
Novice
 
Posts: 3
Liked: never
Joined: Thu Jun 16, 2011 11:24 pm
Full Name: Shane Wendel

Re: Build Jobs Based on vSphere Tags

Veeam Logoby v.Eremin » Fri Apr 25, 2014 9:24 am

$oldbackupobjects = Get-VBRJobObject -Job <JobName> | fl "Name"
Get-VBRJob -Name <JobName> | Get-VBRJobObject -Name $oldbackupobjects | Remove-VBRJobObject

Not sure why you need to repeat the first step (Get-VBRJobObject) second time. Wouldn't it be easier to combine two strings to simple one liner:

Code: Select all
Get-VBRJobObject -Job <JobName> | Remove-VBRJobObject


In order to remove the object from the job, not just exclude it, you should use -Completely switch:

Code: Select all
Get-VBRJobObject -Job <JobName> | Remove-VBRJobObject -Completely


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests