VMware Cloud Community
DMuench
Contributor
Contributor

PowerCLI Get- View Command to get all VMs with tags and its category

Hello Everybody,

I Need to find a way to get the following Information with the get-view Command.

vmName

Tag which starts with VMBCK*

Tag Category

I want to get all vms of a vCenter and need to know which tag that vm has which starts with "VMBCK*". The Output should Show me 3 rows with the named informatione (vmName, Tag, TagCategory)

It would be super if someone could help me.It is important to do this with the Get-View Command.

Thanks in advance

Dominik

2 Replies
LucD
Leadership
Leadership

I'm afraid that is not possible right now.

There is still no public Tag API available afaik. See also William's Custom Attributes != vSphere Tags

The only way to access the Tags is through the PowerCLI cmdlets.

In vSphere 6, as described in KB2130130, Tags are moved from the Inventory DB to the vCenter DB and the Directory Service.

The methods described in that KB, explain how you can queryboth DBs.

With the plink.exe command (from the PuTTY Suite) you could launch that command from a PowerShell session, but I'm afraid that is not for the faint of heart.


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

0 Kudos
vXav
Expert
Expert

I might be wrong but I'm not sure you can work with tag with Get-View.

However here is a one-liner that does what you want:

Get-tag "VMBCK*" | ForEach-Object {$Tag = $_;get-vm -Tag $_ | ForEach-Object {[pscustomobject]@{name=$_.name;tag=$Tag.name;Category=$tag.category}}}