PowerShell script exchange
Post Reply
swendel
Novice
Posts: 3
Liked: never
Joined: Jun 16, 2011 11:24 pm
Full Name: Shane Wendel
Contact:

Build Jobs Based on vSphere Tags

Post by swendel »

(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.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Build Jobs Based on vSphere Tags

Post by veremin »

$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.
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests