Transporting Custom VM Fields Between vCenter Servers

One of my customers recently migrated a bunch of VMs between two vCenter servers.  When they finished, they realized that none of their VMs' custom attributes followed the VMs into the new vCenter environment; apparently those attributes are owned by the vCenter server, rather than stored in the VMX file.  Fortunately, they had an export of their VM inventory that included those custom fields, but they had no idea how to repopulate that data across their horde of VMs.

You can see where this is going... and, as expected, I helped them put together a quick PowerCLI script that would set things straight.  This script takes 2 parameters as input: a CSV file that contains the data from the VM inventory (including each VM Name and columns for each of the custom attributes), and an array of which custom attributes need to be set (since that inventory export file is probably going to contain a lot of columns that aren't custom attributes).

Once it's executed, the script goes through the input file, looking for each specified VM.  If it finds the VM, it then loops through the list of specified custom attributes, checking each one against the setting specified in the input file.  If any of the settings don't line up, it corrects the value of that setting and then moves on.

And, that's pretty much it!  It's a nice simple script that uses loops to hopefully make it nice and dynamic and easy to maintain.  That said, it's something that I put together in a single morning and, while it worked for us here, that's no guarantee that it'll work for you in your environment.  Test thoroughly and ensure that you fully understand what any script that you find on the internet does before you run it in your environment.

Comments

Popular posts from this blog

PowerShell Sorting by Multiple Columns

Clone a Standard vSwitch from one ESXi Host to Another

Deleting Orphaned (AKA Zombie) VMDK Files