So I have been working on a script to import Tags from a CSV into vCenter so we can do batch imports of our vCenter tags (its much easier to edit 1000 rows of a spreadsheet than it is to do it directly in vCenter.)
See: Re: Working with Batch Tags in PowerCLI for the script itself.
The problem I have run into is I now have the import script running properly, but now I require a way to export the updated data to a readable CSV file so I can ensure the data being input is up to date. The issue with the export from powerCLI is how vCenter stores tags. within vCenter, tags are stored as TagCategory/TagName together as an object called $Tag and each $Tag is stored in a different element of the array Get-tagassignment. The problem is the input CSV is split out with each Line consisting of the VMName and which Tags it contains under each category with each category being a column.
so The CSV is as follows:
VMName | Category 1 | Category 2 | Category 3 | Category 4 |
VM1 | | Tag Value | | Tag Value |
VM2 | Tag Value | Tag Value | Tag Value | |
Where the tags in VMWare are stored as follows:
VMName | Category/Tag |
VM1 | Category 2/Tag |
VM1 | Category 4/Tag |
VM2 | Category 1/Tag |
VM2 | Category 2/Tag |
VM2 | Category 3/Tag |
So I am looking for a way to get the current output into the format I need, so I can basically create a cyclic loop so the updated tags can be exported back to the CSV so when the CSV is updated it already reflects any changes (such as additional VMs or Removed VMs)