TA2650 scripts – Part 1 – Profiling your vSphere environment

During VMworld 2009 in San Francisco, Hal Rottenberg and myself presented a session called “TA2650 – Take PowerCLI to the Next Level”. During the session we promised to publish the scripts we showed (and those we did not show due to lack of time).

This is part 1 of these scripts. This script shows and explains how I used PowerShell to export the configuration of my vSphere environment, or part of it, to an XML file.

If you investigate any of the Managed Objects which are based on the ManagedEntity object, in your vSPhere environment, you will notice that all configuration parameters are contained in an object under the property called configuration or configurationEx.

For example within a HostSystem object there is a configuration object.

hostsystem-config

Within a ComputeResource object there is since API 2.5 a configurationEx object.

compute-configEx

If we could “dump” the content in a usable format to an external file, we would have an exact description of the Managed Object on file.

That’s when I came up with the following script. It will start from an vSphere inventory location, and from there it will write all the configuration parameters to an XML file.

The concept of recursively investigating all the properties of a managed object has been done before, in a somewhat different form, by Hugo Peeters. See his List ALL properties and subproperties of a variable in Powershell article.

The following script exports all properties to an XML file.

The script takes a number of parameters that determine what will be exported to the XML file.

vProfile-params

Looking at resulting XML file (which can be quite big depending on the size of your vSPhere environment), you notice that the Hosts & Clusters view on the cluster is present. For each of the cluster elements the XML file also contains all the configuration properties.
clus1-xml

In the Config and ConfigurationEx nodes you can find all the properties of these objects. This gives you an easy and offline method if looking up specific settings and configuration options for the cluster.

ntp-config

The previous screenshot shows how you can, for example,  easily report on the NTP settings of an ESX server.

Another useful feature is that these XML files allow you to keep an audit track of the configuration of your vSphere environment. There are a number of 3rd party tools available that allow you compare XML files.

The XML file also tells you what type a specific property is. For arrays the script uses a special convention to show the array elements. Since an XML nodename can’t contain square brackets, the array elements are shown as Server-0- instead of Server[0].

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.