VMware Cloud Community
Allan_N
Contributor
Contributor
Jump to solution

Tag export data blank

Good afternoon folks, I've been looking at how I can pull some basic tag data along with the VM information and came across a number of scripts here (e.g. Export VM tags example ).
When I run any script the export csv file is empty with regards both the Tag Categories and Tag columns. I've tried a few different scripts that I have found here and they all result in no data being exported.

The environment is built around 6.5 (6.5.0.33000) and using the latest versions of PowerCli etc (downloaded today) to connect and run the scripts.

Am I missing something obvious as I'm newbie to both vmware and powercli.

Any help, ideas or suggestions appreciated. Thanks.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The Tag property in the returned objects is in itself an object.
You could use calculated properties to get the Tag names and Category names

Get-VM | Get-TagAssignment |
Select @{N='VM';E={$_.Entity.Name}},
    @{N='Tag';E={$_.Tag.Name}},
    @{N='Category';E={$_.Tag.Category.Name}} |
Export-Csv -Path .\tags.csv -NoTypeInformation -UseCulture


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

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

When you just run

Get-TagAssignment

is there anything returned with an Entity that is a VM?


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

0 Kudos
Allan_N
Contributor
Contributor
Jump to solution

Hi there... so fixing a hosts file entry gave me some data into the file but for tags I get "com.vmware.cis.tagging.TagAssociationModel" rather than the tag name.
If I use that "Get-TagAssignment" command then I do now get some information and I see some of the tags that I would expect to see for tag & entity. Cheers

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The Tag property in the returned objects is in itself an object.
You could use calculated properties to get the Tag names and Category names

Get-VM | Get-TagAssignment |
Select @{N='VM';E={$_.Entity.Name}},
    @{N='Tag';E={$_.Tag.Name}},
    @{N='Category';E={$_.Tag.Category.Name}} |
Export-Csv -Path .\tags.csv -NoTypeInformation -UseCulture


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

Allan_N
Contributor
Contributor
Jump to solution

Thanks for that, was able to export the tags. I'm just looking through your other scripts/tickets as looking to see if we can export multiple tags for the same virtual machine to different columns or if we will need to export all and then manipulate it in Excel to build out the export.

Sure I saw a similar request so will check that out. Thanks again

0 Kudos