Tuesday, August 6, 2013

Using Powershell to Create/Clone Clusters to new vCenter...vCenter 5.1 migrations part 3

Ok, so it has been a awhile, for good reasons though...vacation was good!  Somehow we admins, when we leave all of our work is waiting for us when we return...and then some (can I get an amen)?  Now that I am caught up with my daily admin duties lets take a look at the next steps.

It saved some code by putting together the cluster creation for both SDRS clusters and DRS clusters in one small script.  This script would be needed to create the clusters prior to importing any settings for either DRS or SDRS.  I will be doing the SDRS post next.

This script assumes that both source and target vCenters are up and running as it will connect to both and read from the source and write to the target:


param(
 [Parameter(Mandatory=$true)] $SourceVIserver = $(Read-Host -prompt "VIserver?"),
 [Parameter(Mandatory=$true)] $DestinationVIserver = $(Read-Host -prompt "VIserver?")
 )

$svc=connect-viserver $SourceVIserver
$dvc=connect-viserver $DestinationVIserver

#Clone Clusters from source to target
$sclusters=get-cluster -server $svc|sort name
$dc=get-datacenter -server $dvc

foreach ($cluster in $sclusters)
{
 new-cluster -location $dc -server $dvc -name ($cluster.name) -DRSEnabled -DRSautomationlevel "PartiallyAutomated" -confirm:$false
}

$dscs=get-datastorecluster -server $svc|sort name
foreach($dsc in $dscs)
{
 $newdscFolder = get-folder -server $dvc -name ((get-folder -server $svc -id ($dsc.extensiondata.parent)).name)
 $dscl=new-datastorecluster -location $newdscFolder -name ($dsc.name)
 $dscl|set-datastorecluster -SdrsAutomationLevel Manual
}

disconnect-viserver * -confirm:$false -force


*** Notice that when I created the DRS clusters I forced the cluster DRS automation level to Partial, the last thing I wanted was anything moving around during my upgrade.

The first foreach loop creates the DRS clusters and the second creates the SDRS clusters.  There is a bit more code in the second loop because our SDRS clusters are contained in folders for security and organization reasons.  We of course wanted things to be back the way they were.  This could have been done for the DRS clusters, but our DRS clusters were not in folders, so I just kept the code shorter.

Ok, so now we have:
- VM Details in a CSV file (post)
- DRS details in a CSV file (post)
- DRS and SDRS clusters created in our new vCenter

No comments:

Post a Comment