Complex Script – Rename vDS attached hosts from IP to DNS Name

SCRIPT SYNOPSIS / REASON CREATED — We have several hundred hosts in various DCs around the world, and the majority of these hosts were connected to vCenter via the IP address rather than the DNS Name, which we wanted to change.  We are running vSphere ESXi 5.5 on all hosts, and each host is connected to a site vDs, which added complexity to this renaming process.  This “complex” script is comprised of seven separate steps and should be run on hosts that are already in Maintenance Mode.

OVERVIEW OF STEPS — After manually putting the host(s) into Maintenance Mode, the script below connect to vCenter, migrate the host(s) from the vDS to a vSS, remove the host from the vDS (after the physical NICs are attached to the vSS), take the IP address of the host(s) and perform a reverse-DNS Lookup which is then piped out to a variable, remove the host(s) from vCenter, add the host(s) back to vCenter using the DNS variable previously created, add the host(s) back to the existing vDS and migrate the vmk ports and physical NICs from the vSS back to the vDS, and then disconnect from the vCenter.