Migrating ESXi Hosts to Another vCenter Server
As part of a migration project, ESXi hosts needed to be migrated to a new vCenter appliance. The Cisco 1000v distributed virtual switch was stripped out and converted to standard switches. So basically it was a matter of disconnecting, and removing the hosts from the old vCenter and adding them to the new vCenter inventory. But with more than 150 hosts I didn’t want to do it manually. So I put together a script… Please be aware that the script contains some specific code that you will need to customize to get it to work in your environment.
The script uses two parameters: Cluster and Root Folder. Cluster is specifying the cluster. Root Folder is for pointing to the root folder of the VM folders. This was necessary because there were duplicate folder names.
After connecting to both vCenter Servers I save the DRS host rules and VM rules. I also save the DRS VM groups. That was not necessary for the Host groups.
Then it is time to do the actual migration. For every host in the cluster I perform the following steps:
- Create a file with VMs and folder paths
- Disconnect the host from the source vCenter Server
- Remove the host from the source vCenter Server
- Add the host to the destination vCenter Server
- Move the host to the cluster on the destination vCenter Server
- Move the VMs to their own folder
When the previous steps are done, I create the DRS Host groups and VM groups and enable DRS on the cluster on the destination vCenter Server.
Finally, I create the DRS VM rules and disconnect from both vCenter Servers.