VMware Cloud Community
Gabrie1
Commander
Commander
Jump to solution

Get-TagAssignment

Hi

How can I get a list of VMs that have a tag of the category "Location" and not present VMs that don't have this tag.


Get-TagAssignment -Entity $vm -Category "Location"

Will only list all tags.

I can't use:   $vmlist = get-vm | Get-TagAssignment -Entity $vm -Category "Location"

And when I have this list, I of course want to filter on VMs from a specific location.... 🙂

Any tips?

Gabrie

http://www.GabesVirtualWorld.com
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

Alternatively you can do it like this:

$tags = Get-Tag -Category "Location"

Get-VM -Tag $tags

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Can't you do something like

Get-VM | Where {$_ | Get-TagAssignment | Where {$_.Tag.Category -eq "Location"}}


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

admin
Immortal
Immortal
Jump to solution

Alternatively you can do it like this:

$tags = Get-Tag -Category "Location"

Get-VM -Tag $tags

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which is much more elegant than my Where-clause construction Smiley Happy


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

0 Kudos
Gabrie1
Commander
Commander
Jump to solution

Thank you both !!!

http://www.GabesVirtualWorld.com
0 Kudos