posted

4 Comments

It has been an exciting year (and a couple months) for the DSC Resources for VMware. As of last week’s announcement, there have been 3 releases for a total of 67 resources for this open source project. It has been presented to many different audiences, including VMworld US and Europe, PowerShell Conference Europe, PowerShell Conference Asia, and several PowerShell and VMware User Groups! And the number one question we always get: how do I pull my existing configuration?

This is a tricky conversation. One which normally starts as a discussion and ends in a debate, because there’s no wrong answer. If you think about a vSphere environment, there are a lot of settings. Some of those settings are that way by default, while others have been configured to be as such. In a majority of situations, an export is going to include all of the available settings, regardless of whether they’re there by default or not. From that point forward, it is your choice whether to continue monitoring the configuration of those settings. Regardless of your preference, we have an amazing new tool that was created to help ease the process of exporting an existing configuration.

Let’s check out a new way to export an ESXi host’s configuration for use with PowerShell DSC.

Introducing the ExportVMHostConfiguration Script

As of version 2.1 of the DSC Resources for VMware, there is a script included in the root folder of the module directory on GitHub. This script is called ExportVMHostConfiguration.ps1. This script is going to connect to your server, whether that be a vCenter Server or ESXi host directly, and it is going to pull back the configuration of the specified ESXi host.

Input parameters:

  • Server – Connection point for PowerCLI, either a vCenter server or an ESXi host
  • Credential – Credentials which will be used against the Server
  • VMHostName – Name of the host of which the DSC configuration will be exported
  • Path – Location to store the DSC configuration once the export has completed

When running the script, it will connect to the system supplied in the Server parameter, then output to the terminal each section which is being gathered, and finally will close the connection the to the system supplied in the Server parameter.

Running the script will look similar to the following:
Sample: Exporting an ESXi host's configuration to DSC

After the script has successfully completed, check the directory which was referenced for the Path parameter. There should be a single PowerShell file which, when opened, will contain the configuration for your specified host!

Sample: Output from a DSC export process

There are a couple caveats we should mention. The exported configuration only includes information for resources which have been completed. For example, DSC resources for vSphere Distributed Switches (VDS) are still being worked on therefore they will not show up in this exported configuration at this point in time. Each of the resources which have been populated will include all the properties for those resources, even the ones that are not required. We can see additional information about each resource, including the available properties in the GitHub repository’s Documentation directory.

One known issue we have run into, a PowerShell session may terminate. We have found that increasing the memory available to the PowerShell process has helped to alleviate the issue. Running the following command has helped with the issue:

Depending on your environment, you may want to set that back to the default of 1024 after the export process has completed. This can be done with the following command:

Summary

The DSC Resources for VMware 2.1 release had a hidden surprise in the GitHub repository, a way to export an ESXi host’s configuration as a DSC configuration file! This script, named ExportVMHostConfiguration.ps1, can be found in the root of the VMware.vSphereDSC folder. By running the script with a few input parameters, you will receive back that host’s configuration as it would be written for PowerShell DSC!

Download the ExportVMHostConfiguration.ps1 script from the GitHub repository today, and let us know in the comments how it’s working in your environment!