Hey scripters! I recently had a task of migrating an entire virtual datacenter from one vCenter to another. It sounds like a pretty simple task, but manually recreating the cluster(s) could cause some human errors. I decided to write a script that would look at a specific vDatacenter and get all it’s clusters, then recreate that tree in the new vCenter. It’s pretty simple, really, it pulls all the clusters, then creates new clusters with the same attributes. When moving over the hosts, it first disconnects them from the original vCenter, then removes them from inventory.

I thought about disabling HA & DRS on the source vCenter cluster right before hand, but manually disconnecting & removing shouldn’t be an issue. If you add the host to the new vCenter without first removing from the old vCenter, that’s when you’ll get some HA weirdness because the old vCenter doesn’t know what just happened.

What does it do?

Simple. It looks that the vDatacenter name provided, gets all clusters & host in it. From there, it creates a new vDatacenter with the same name in the new vCenter, then recreates all the clusters. Here it actually uses the attributes of the original cluster when creating the new ones to get them as close as possible. Last, it adds the hosts back to their cluster, but in the new vCenter.

One nice thing is it also handles EVC mode.

If you have a central password repository, you could have the script pull from there, but I just had it prompt for username & password to add to the new vCenter.

What it doesn’t do.

  • Resource Pools
  • Permissions
  • DRS Rules & Groups
  • DRS Automated Migration Threshold
  • Or any other advanced cluster settings

It looks at the basic cluster settings that you can set via PowerCLI when creating a cluster. It does enable HA & DRS, but anything advanced, you’ll have to adjust.

I tried the resource pools thing, it’s kind of tricky, but hopefully I’ll get that going soon. I tried the same approach as the clusters, powershell/powercli complained about a few things, no matter how I did it.

Permissions should be easy, but will really depend on the new vCenter if all the roles & if everything’s set up identical.

DRS Rules & Groups shouldn’t be that hard, but I haven’t messed with it, and unfortunately, there’s no PowerCLI access to the migration threshold. You know, that little slider with “Conservative” and “Aggressive”, it just plops it right in the middle.

Where’s the script?

Right here (DOWNLOAD):

Have fun, and happy scripting!!!