preloader
2 August 2013 / #Powercli

Replicating custom fields

The VMware platform on which we now work with hypervisor.fr has several specific aspects and one of them is having a lot of custom fields.

customfields_01

Besides wanting consistency in all these custom fields, we like to have a clean production platform and therefore it is preferable to have a N/A custom field instead of a empty one (to avoid custom alerts), and avoiding oversights in OVF appliance deployment (which does not fill fields automatically).

mrpropre

So we developed a PowerCLI script which will replicate, if needed, custom fields and annotation from one VM to another in order to make your life easier, and mainly to avoid potential errors with manual input. You can also use it to fill up the VM’s custom fields with N/A (if parameter vmSourceName isn’t used).

The script takes the following arguments :

  • vmSourceName (optional) : Name of the VM used for source replication
  • vmDestinationName : Name of the VM used for destination replication
  • force (optional) : This switch allows you to overwrite destination custom field

First of all, there is some checks in order to verify the source and destination VM exists:

set-tags_02

Then comes the replication of custom fields and annotation. If destination’s VM already has some filled custom field, they will not be overwritten except if you’re using the -force switch:

set-tags_03

Here are some example:

C:\foo>.\Set-Tags.ps1 -vmSourceName VM01 -vmDestinationName VM02

This will replicate custom field from VM01 to VM02 (without overwriting destination).

C:\foo>.\Set-Tags.ps1 -vmSourceName VM01 -vmDestinationName VM02 -force

This will replicate custom field from VM01 to VM02 (with overwriting destination).

C:\foo> .\Set-Tags.ps1 -vmDestinationName VM02

Fill custom field from VM02 with N/A string (without overwriting destination).

C:\foo> .\Set-Tags.ps1 -vmDestinationName VM02 -force

Fill custom field from VM02 with N/A string (with overwriting destination).

And as always, you can use Get-Help in order to get online help for the cmdlet:

set-tags_01

The Set-Tags.ps1 script is available for download in our GitHub page: https://github.com/v-team/powercli-toolbox


> Frederic MARTIN