VMware Cloud Community
brrupnick
Contributor
Contributor
Jump to solution

Show VMs with Multiple Tags in a Category

Good afternoon-

I'm looking for a way to list all VMs that have multiple tags from a certain category. In my situation, I'm using VMware tags to control the selection lists for my backup software. I have a tag category called "Backup Job" and tags called "Monday," "Tuesday," etc. I'm  looking for a script that will tell me all the VMs that have multiple tags from the Backup Job category, like the "Monday" and "Thursday" tags, for example.

Thank you!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$tagCatName = 'Backup Job'

$tagCat = Get-TagCategory -Name $tagCatName

Get-VM | where {(Get-TagAssignment -Entity $_ -Category $tagCat).Count -gt 1} |

Select Name,

  @{N="Tags";E={[string]::Join(',',(Get-TagAssignment -Entity $_ -Category $tagCat | %{$_.Tag.Name}))}} 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$tagCatName = 'Backup Job'

$tagCat = Get-TagCategory -Name $tagCatName

Get-VM | where {(Get-TagAssignment -Entity $_ -Category $tagCat).Count -gt 1} |

Select Name,

  @{N="Tags";E={[string]::Join(',',(Get-TagAssignment -Entity $_ -Category $tagCat | %{$_.Tag.Name}))}} 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
brrupnick
Contributor
Contributor
Jump to solution

PERFECT!! Thank you so much!!

0 Kudos