Generating SSL Certificates for ESXi Hosts using PowerShell

If you have ever had to generate SSL certificates for all of your hosts, you know that this is no trivial task, especially if you have a large environment. I wrote a script that generates the CSR, converts the key to RSA, and requests the certificate from the CA. It puts everything neatly into c:\certs\hosts\hostname so you can keep it with the certs from the rest of VMware’s recommended SSL path. I am making the assumption that if you are reading this you are somewhat familiar with the process for the other components and these concepts are not foreign.

The first step is to create the OpenSSL cfg files, one for each host. These are in the same format that is used for all of the other components. I have not yet created a script to generate these, but if I do I’ll add it here. I created a folder at c:\certs\hosts\opensslcfg to store the cfg files with the naming convention of hostname.cfg.

My script makes the following assumptions:

You have created an openssl cfg files for each host

You have the proper version of openssl installed to c:\openssl (if not, just change the path in the script)

You are using a Microsoft CA

You know what certificate template you want to use (same as used for other components)

You have access to request the certificates

There are plenty of ways you could feed hostnames into the script, I just used a CSV exported from an Excel spreadsheet that I use to keep track of my environment. The CSV looks something like this:

After the certificates have been generated, all that is left is to install them. This requires putting the host in maintenance mode, copying the appropriate rui.crt and rui.key to /etc/vmware/ssl on each host, and then restarting the management agents. Here is the official VMware KB article on the subject.