VMware Cloud Community
mauropappaterra
Contributor
Contributor

Having trouble retrieving tags from vCenter VMWare virtual machine on .NET

Hello, I am trying to retrieve the tags from each of the virtual machines on vCenter for a project I am writing for the company I work for. I succesfully have set up the .NET environment with PowerCLI and I can successfully retrieve all VM with name and such, but when I try to get the tags, I get an empty array.

// Connect to VMware SDK service

Client.Connect(address_vmw);

Client.Login(username_vmw, password_vmw);

// Get all Virtual Machines

vmw_machines = Client.FindEntityViews(typeof(VirtualMachine), null, null, null);

foreach (VirtualMachine machine in vmw_machines) //for each machine in VMW

{

string machineName = machine.Name; // this works fine

dynamic machineTags = machine.Tag; // I need to fix this line!

foreach (dynamic tag in machineTags) // it is an empty array!

{

   Console.Write(tag);

}

...

This are the tags I need to retrieve on vCenter:

tags.jpeg

Tags (2)
0 Kudos
1 Reply
kkzinger
Contributor
Contributor

Hello,

I discovered the same problem. I am writing a PowerCLI script for retrieving Tags from VMs.
In the VM object (retrieved with Get-VM) under ExtensionData.Tag there is also an empty Array.

After that I tried retrieving the VM via Get-View with the same result.

One workaround I found was to use $VMobject = Get-VM and Get-TagAssignment -Entity $VMobject

I do not like this solution due to performance decrease in comparison to the Get-View approach.

0 Kudos