PowerShell script exchange
Post Reply
Crashinit
Influencer
Posts: 13
Liked: never
Joined: Nov 10, 2016 9:58 pm
Full Name: Craig Connoll
Contact:

Add TAGS to Objects to exclude

Post by Crashinit » Feb 12, 2019 1:59 am

Hi All,

I'm hoping someone can help.
I've tried searching the forums and using code out there, but i'm just not getting anywhere.

I have Backup Copy Jobs that I need to add Exclusions too.
These Exclusions must be a combination of TAGS and DataCenters.
It is easy to do this via the GUI, but when I have loads of Jobs and multiple backup servers to manage, it gets a bit long in the tooth.
I have been able to get the Backup Copy Jobs configured with powershell and this is the only setting i'm struggling with.

Any help will be much appreciated.

jhoughes
Veeam Software
Posts: 91
Liked: 21 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Add TAGS to Objects to exclude

Post by jhoughes » Feb 12, 2019 3:09 am

Took me a few minutes to run through the overload definitions to create this, but here it is with an example from my lab.

First, create the variables for the empty properties and the 'Exclude' type required by the Update method of the [Veeam.Backup.Core.CObjectInJob] object:

Code: Select all

$vss = [Veeam.Backup.Model.CGuestProcessingOptions]::CreateDefaultForObject($false)
$diskfilter = [Veeam.Backup.Model.CDiskFilterInfo]::CreateEmpty
$exclusion = [Veeam.Backup.Model.CDbObjectInJobInfo+EType]::Exclude

Here's my job before adding the 'VeeamReplication' tag object:

Code: Select all

$job | Get-VBRJobObject

Name                      Type       ApproxSize       Location
----                      ----       ----------       --------
VeeamTagTest              Include    142.4 GB         ausvcenter.lab.fullstackgeek.net\VeeamBackup (Tags for Backup Jobs)\VeeamTagTest (Job Tag for Veeam Backups)

Next, I run the code to add the new 'VeeamReplication' tag and look at the job objects, to verify it is the default 'Include' type.

Code: Select all

$job = Get-VBRJob -Name 'AUSVCENTER-TagTest'
$tag = Find-VBRViEntity -Name 'VeeamReplication' -Server (Get-VBRServer -Name ausvcenter.lab.fullstackgeek.net) -Tags
Add-VBRViJobObject -Job $job -Entities $tag

$job | Get-VBRJobObject

Name                      Type       ApproxSize       Location
----                      ----       ----------       --------
VeeamTagTest              Include    142.4 GB         ausvcenter.lab.fullstackgeek.net\VeeamBackup (Tags for Backup Jobs)\VeeamTagTest (Job Tag for Veeam Backups)
VeeamReplication          Include    0.0 B            ausvcenter.lab.fullstackgeek.net\VeeamReplication (Tags for Replication Jobs)

Lastly, I capture the object to be set to an 'Exclude' type, run the Update method of the job object, and here is the final result of the job objects:

Code: Select all

$exclude = $job | Get-VBRJobObject -Name 'VeeamReplication'
$exclude.Update($vss,$diskfilter,$true,$exclusion)

$job | Get-VBRJobObject

Name                      Type       ApproxSize       Location
----                      ----       ----------       --------
VeeamTagTest              Include    142.4 GB         ausvcenter.lab.fullstackgeek.net\VeeamBackup (Tags for Backup Jobs)\VeeamTagTest (Job Tag for Veeam Backups)
VeeamReplication          Exclude    0.0 B            ausvcenter.lab.fullstackgeek.net\VeeamReplication (Tags for Replication Jobs)
This should help you to set your exclusions. You'll need to run this once per job object (for each object in the job to be excluded) to flip it to an 'exclude' type.

You may want to create a collection of your servers, jobs and tags to be excluded, then you'd only have to loop through it once to run the Update method per object in your collection.
Husband, Father, Solutions Architect, Geek Extraordinaire | @AustinVMUG & @ATXPowerShell leader | vExpert | Cisco Champion | Tech Field Day Delegate | VCP 4/5/6 | VCP6-NV | VMware/Cisco UCS/Powershell/VEEAM Enthusiast

Crashinit
Influencer
Posts: 13
Liked: never
Joined: Nov 10, 2016 9:58 pm
Full Name: Craig Connoll
Contact:

Re: Add TAGS to Objects to exclude

Post by Crashinit » Feb 12, 2019 3:55 am

Hi jhoughes,

Thanks for the Update.

I have tested the code, but i'm getting the following error:

When creating the variable $diskfilter I get the below Error.

Code: Select all

Unable to find type [Veeam.Backup.Model.CDiskFilterInfo].
At line:7 char:15
+ $diskfilter = [Veeam.Backup.Model.CDiskFilterInfo]::CreateEmpty
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Veeam.Backup.Model.CDiskFilterInfo:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound
The the last error is:

Code: Select all

Unable to find type [Veeam.Backup.Model.CDiskFilterInfo].
At line:7 char:15
+ $diskfilter = [Veeam.Backup.Model.CDiskFilterInfo]::CreateEmpty
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Veeam.Backup.Model.CDiskFilterInfo:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound
 
Exception calling "Update" with "4" argument(s): "Object reference not set to an instance of an object."
At line:15 char:1
+ $exclude.Update($vss,$diskfilter,$true,$exclusion)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException
The end result is that the TAGS are added to the "Objects to Process" but not flipped to the exclusions Objects

jhoughes
Veeam Software
Posts: 91
Liked: 21 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Add TAGS to Objects to exclude

Post by jhoughes » Feb 12, 2019 1:55 pm 1 person likes this post

I should have specified that I'm running U4, although the type name should exist for you.

Either way, I realized this morning that I forgot the easy way to so this. The Remove-VBRJobObject cmdlet will actually set an exclusion if you don't use the -Completely switch parameter.

Just run the code for Add-VBRViJobObject, then get that same object and pipe it to Remove-VBRJobObject. It should set the object as an exclusion.

Apologies if there a typo, typed from cell phone.
Husband, Father, Solutions Architect, Geek Extraordinaire | @AustinVMUG & @ATXPowerShell leader | vExpert | Cisco Champion | Tech Field Day Delegate | VCP 4/5/6 | VCP6-NV | VMware/Cisco UCS/Powershell/VEEAM Enthusiast

tsightler
VP, Product Management
Posts: 5374
Liked: 2208 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Add TAGS to Objects to exclude

Post by tsightler » Feb 13, 2019 4:56 pm 1 person likes this post

Either way, I realized this morning that I forgot the easy way to so this. The Remove-VBRJobObject cmdlet will actually set an exclusion if you don't use the -Completely switch parameter.

Just run the code for Add-VBRViJobObject, then get that same object and pipe it to Remove-VBRJobObject. It should set the object as an exclusion.
Yep, I sometimes joke that this is perhaps the worst named cmdlet in Powershell history, a "remove" cmdlet that, by default, doesn't actually perform a remove of anything, and then requires some fairly strangely named flag to actually remove the object. But it's difficult to fix due to the fact that it's been around a long time and lots of code now depends on the existing behavior.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest