VMware Cloud Community
ranjitcool
Hot Shot
Hot Shot

Remove and add to Virtual Centers

Hey Guys,

I have a project where I have to manually move hypervisors from one Virtual center to another.

Now I am thinking if I can script this and have the following questions.

1. Can this be scripted in power cli - with options like - if hyp is in a cluster - create the cluster on other vc as well and so on.

2. I have never created scripts in power cli that actually alter stuff in vcenter, so is this the safe programming medium to do so?

3. If this can be done, how do I send pre confirm command where the new vcenter will warn you about loosing data as you are moving a hyp that is registered to another vcenter?

Please advise.

RJ

Please award points if you find my answers helpful Thanks RJ Visit www.rjapproves.com
Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

1. Yes, you could do something like this

$hypervisors = "esx1","esx2"
$oldVC = "vcenter1" 
$newVC = "vcenter2"
$connectOld
= Connect-VIServer -Server $oldVC
$connectNew = Connect-VIServer -Server $newVC
$hypervisors
| %{     $esx = Get-VMHost -Name $_ -Server $connectOld
   
$cluster = ($esx | Get-Cluster).Name     $newCluster = Get-Cluster -Name $cluster -Server $connectNew -ErrorAction SilentlyContinue
   
if(!$newCluster){         $newCluster = New-Cluster -Name $cluster -Server $connectNew
    }    
Remove-VMHost -VMHost $esx -Server $connectOld -Confirm:$false
    Add-VMHost -Name $esx.Name -Server $connectNew -Confirm:$false -Location $newCluster
}

Note that this is just a general template for what you want to do. The script most probably needs some tuning.

2. Yes. PowerCLI is using underneath the same methods the GUI is using

3. Do you mean a message on the screen ? That can be done with a Write-Host cmdlet for example.

Write-Host "Moving a hypervisor might loose data"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos