addHostCustomField.pl

addHostCustomField.pl

This scripts allows you to automate the updating of custom fields for ESX(i) host(s) managed by vCenter.

Requirements:

  • vCLI or vMA 4.x
  • ESX(i) 4.x managed by vCenter 4.x

Download Script:

addHostCustomField.pl

Setup:

The script allows you to update multiple custom fields for an ESX(i) host, it will assume the actual custom fields have already been defined within vCenter and that you would like to bulk update the custom fields. The script accepts a config file in the following format:

-> The first line is the actual name of the custom field, this needs to be in the order in which you have the values listed and you will need to separate them using a comma

-> The lines after will designate the name of ESX(i) host name which is displayed within vCenter, followed by the custom values based on the order specified in the first line of the config file.

Let's say you have two custom fields called "Location" and "PID" and you have 3 ESX(i) hosts named esx4-4, esx4-5 and himalaya and you would like to update their fields in the following way:

ESX(i) HostLocation Custom FieldPID Custom Field
esx4-4.primp-industries.comSanta Barbara C11234
esx4-5.primp-industries.comSanta Barbara C25678
himalaya.primp-industries.comSanta Barbara C39000

You will then need to create a config file that looks like the following:

[vi-admin@tancredi ~]$ cat conf
Location,PID
vihost=esx4-4.primp-industries.com;'Santa Barbara C1'@'1234'
vihost=esx4-5.primp-industries.com;'Santa Barbara C2'@'5679'
vihost=himalaya.primp-industries.com;'Santa Barbara C3'@'9000'
You will need to quote your custom fields if they have spaces and you need two seperate the hostnames with the actual custom keys using ";" and "@", these characters are place holders that is used to parse each line.
Here is a sample execution of the script which you will connect to your vCenter server:
[vi-admin@tancredi ~]$ ./addHostCustomField.pl --server reflex --config .primp.vc --operation update --input conf
Updating esx4-4.primp-industries.com custom fields ...
Updating esx4-5.primp-industries.com custom fields ...
Updating himalaya.primp-industries.com custom fields ...
After you have executed the script, you should now see these fields populated for your ESX(i) host in vCenter.
Version history
Revision #:
1 of 1
Last update:
‎01-24-2011 10:06 PM
Updated by: