Cloning Datacenters between 2 vCenters with PowerCli, including permissions and many more

Usually when updating your vCenter infrastructure you perform upgrade in place. But you can also opting for a migration from your actual vCenter to a freshly installed one. One “good” reason for going to migration is changing the type of underling Database used by vCenter. I had to “get rid of” an Oracle DB to go on a MSSQL one.

Another reason, which came with the version 5 of vSphere, is the VMware vCenter Server Appliance, if you want to “get rid of” your Windows’ vCenter.

Which can be taken into consideration now. Since View 5.1, the Composer can be installed on another Windows server than vCenter. VUM can also be installed on a separate Windows server.

Of course by doing such migration you will have extra work to migrate your Hosts and VMs and you will lose the performances history of your whole infrastructure, unless you export them before.

For my case the source vCenter was running the 2.5 and the destination 4.0. The complete infrastructure was composed of 35 hosts with ~400 VMs.

The first challenge was about the quite advanced VM folders and resource pools structure on my source infrastructure. A lot of folders with a lot of different permissions. Replicating these structures manually wouldn’t have been a piece of cake, including the risks of human errors.

So naturally I decided to request the help of every Virtual Admins’ best friend:“PowerCli”

The prerequisites for having the following script running are:

– Both vCenters must be in the same domain
– Permissions set to Domain users/groups
– The roles existing and used on the “source” vCenter must exists on the “destination” one (I’ve made a script that check and list the differences for the roles between 2 vCenters -> roles_comparison_between_2_vCenters )
– The account you are going to use with these scripts must have administrator access to both vCenters.

I made a script that duplicate an entire DataCenter between 2 vCenters.

DataCenter_Duplication_between_2_vCenters

My script has been adapted for the PowerCli 5.0 and can be applied against vCenter 4.0 and later.

Let’s start.

We have a source Data center that we want to duplicate to another vCenter

You can see that a permission is set at the DC level

The cluster Clstr-01 has also some settings that will be duplicated additionally to the permissions

For example the admission control. But I will come back later at it.

In the VMs and Templates several folders have been created with different permissions set also.

The script also duplicates the folders created in the datastores and networking

Now, in the destination vCenter you can see that it is totally empty

Now let’s run the script

Remember, the user with which the script will run must have the administrator role at the top level of both vCenters.

After being logged on both vCenters, enter the name of the DataCenter you want to duplicate.

Now if we check on the destination vCenter:

Every component (DataCenter, cluster, RP, folders) has been duplicated with their permissions:

So duplication of the DataCenter, Cluster, RP and folders with their respective permission went fine. But it is not the only things that I duplicate:

On the cluster the HA and DRS states are also duplicated with the following settings:

(PowerCLi reference Set-Cluster)

HA:

– If HA is enable
– HAFailoverLevel
– HAAdmissionControlEnabled
– HAIsolationResponse
– HARestartPriority

DRS:

– If DRS is enable
– DrsAutomationLevel

Now if we really compare both settings for the cluster.

HA:

DRS:

And finally the Resource Pools have also the share duplicated. Not the reservations and limits because of the absence of host (resources) in destination the cluster of course.

 

Enjoy!

Leave a Comment

*

code