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.

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).

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:

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:

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:

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

2 comments

  1. Bom dia, estou utilizando o comando abaixo para alterar o customfields das pastas, porém não está replicando para as pastas “filho” alguém sabe como fazer isso pelo powercli?

    Get-Folder ‘nome_da_pasta’ | Set-Annotation -CustomAttribute Contato -Value e-mail

    Obrigado

Leave a Reply to Ammesiah Cancel reply

Required fields are marked *.