PowerShell script exchange
Post Reply
orb
Service Provider
Posts: 126
Liked: 27 times
Joined: Apr 01, 2016 5:36 pm
Full Name: Olivier
Contact:

Find-VBRViEntity -Tags

Post by orb »

Hi,

The doc states
Exemple 4 This command looks for the list of VMs having a VMware tag named "Mac OS" within a particular host. The host is obtained with Get-VBRServer and assigned to the '$server' variable beforehand.
The reality returns only the tag object (CViTagItem) which is correct if you read the description
Indicates that the cmdlet will return only tags.Use the Name parameter to specify the tag name
CViTagItem isn't listed on the possible returned object https://helpcenter.veeam.com/docs/backu ... ml?ver=100

Do we have another way to achieve the example?

Oli
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Find-VBRViEntity -Tags

Post by jhoughes » 2 people like this post

If your question is about getting the VMs objects which have the tag assigned, then no, only the tag entity itself will be returned if you query by a tag name.

As for the documentation, that type is missing from the list, but is it the object type returned:

Code: Select all

$vc = Get-VBRServer -Name 'ausvcenter.fsglab.local'
$Tag = Find-VBRViEntity -Server $vc -Tags -Name "VeeamTagTest"
$Tag.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     CViTagItem                               System.Object

$Tag | gm

   TypeName: Veeam.Backup.Core.Infrastructure.CViTagItem

If you need to query VMs with a specific tag, you'd need to capture all of the tag objects first and compare to the path of the specific tag that you are trying to match (tag to be matched in below example is 'VeeamTagTest'):

Code: Select all

$TagName = "VeeamTagTest"

$vc = Get-VBRServer -Name 'ausvcenter.fsglab.local'
$AllTags = Find-VBRViEntity -Server $vc -Tags
$SpecificTag = $AllTags | Where-Object {$_.Name -eq $TagName -AND $_.Type -eq 'Tag'}
$AllTags | Where-Object { $_.Path -like "$($SpecificTag.Path)*"}

(Results shortened for space)

Type        : Tag
Reference   : urn:vmomi:InventoryServiceTag:76fce34f-b97d-426d-95fd-8a659038a4da:GLOBAL
TagQsId     : urn:vmomi:InventoryServiceTag:76fce34f-b97d-426d-95fd-8a659038a4da:GLOBAL
Id          : 5000abb5-f13d-4434-a48d-bec0763f68f3_urn:vmomi:InventoryServiceTag:76fce34f-b97d-426d-95fd-8a659038a4da:GLOBAL
Name        : VeeamTagTest
Path        : ausvcenter.fsglab.local\VeeamBackup\VeeamTagTest
Description : Job Tag for Veeam Backups

Type                   : Vm
Name                   : ausvcenter
Path                   : ausvcenter.fsglab.local\VeeamBackup\VeeamTagTest\ausvcenter

Type                   : Vm
Name                   : ausdc01
Path                   : ausvcenter.fsglab.local\VeeamBackup\VeeamTagTest\ausdc01

Type                   : Vm
Name                   : ausveeambr
Path                   : ausvcenter.fsglab.local\VeeamBackup\VeeamTagTest\ausveeambr
I'll send a note to the docs team to update the list to include the 'CViTagItem' type.
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Find-VBRViEntity -Tags

Post by jhoughes » 1 person likes this post

Edit to the previous post. The last code example above will give you the original tag object, and all associated child objects.

If you want the VMs only, use this code:

Code: Select all

Find-VBRViEntity -Server $server -Tags -Name ""

$TagName = "Mac OS"
$AllTags = Find-VBRViEntity -Server $server -Tags
$SpecificTag = $AllTags | Where-Object { $_.Name -eq $TagName -AND $_.Type -eq 'Tag' }
$AllTags | Where-Object { $_.Path -like "$($SpecificTag.Path)*" -AND $_.Type -eq 'VM' }
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Find-VBRViEntity -Tags

Post by oleg.feoktistov »

Adding to Joe's advice, you could also query tag assignments for a particular tag with PowerCLI and then compare tag assignment entities (VMs) with CViVmItems from VBR:

Code: Select all

$connection = Connect-ViServer -Server vCenterServerName -Credential $creds
$tags = Get-TagAssignment -Server $connection.Name | where {$_.Tag.Name -eq 'TagName'}
foreach ($tag in $tags) {
Find-VBRViEntity -Server vCenterServerName -VMsAndTemplates -Name $tag.Entity
} 

The reality returns only the tag object (CViTagItem) which is correct if you read the description
Make sure to click Send Feedback at the bottom of the page if you feel like the article's content can be improved.

Thanks,
Oleg
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Find-VBRViEntity -Tags

Post by jhoughes »

Feedback has been submitted to correct the language for example 4, along with adding a new example to show how to return the VMs which have a specific tag assigned.
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
orb
Service Provider
Posts: 126
Liked: 27 times
Joined: Apr 01, 2016 5:36 pm
Full Name: Olivier
Contact:

Re: Find-VBRViEntity -Tags

Post by orb » 1 person likes this post

@jhoughes, thanks! I should have thought this. The snapin requires often output processing outside the command itself. Let's hope they improve the situation the day we get a proper module :)
@oleg.feoktistov, I didn't notice the feedback button :) Next time! jhoughes solution suits perfectly my needs and it doesn't require to query a second source.

Regards,
Oli
Refruit
Service Provider
Posts: 34
Liked: 2 times
Joined: Feb 27, 2020 6:38 am
Contact:

Re: Find-VBRViEntity -Tags

Post by Refruit »

Hello,

sorry to revive the dead but i have an issue here.
Today we upgraded our Veeam to the latest version from December.

The following code was working up until now:

Code: Select all

Find-VBRViEntity -Server $server -Tags -Name ""

$TagName = "Mac OS"
$AllTags = Find-VBRViEntity -Server $server -Tags
$SpecificTag = $AllTags | Where-Object { $_.Name -eq $TagName -AND $_.Type -eq 'Tag' }
$AllTags | Where-Object { $_.Path -like "$($SpecificTag.Path)*" -AND $_.Type -eq 'VM' }
Since the update we are not getting the associated child objects anymore.


if i compare those entries:
https://helpcenter.veeam.com/archive/ba ... ntity.html
https://helpcenter.veeam.com/docs/backu ... ml?ver=110

Example 5. Getting List of VMs with Specific VMware Tags has been removed. I would love to know why and whats the alternative here...
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Find-VBRViEntity -Tags

Post by oleg.feoktistov »

Hi,

Yes, we are aware of this issue. Please see my reply here.

Thanks,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests