Am trying to migrate Esxi host from one vCenter to another vCenter
Backup vDS from Source vCenter with Port Group Identifiers
Import the backed up vDS on New vCenter
Disconnect the host from Old vCenter and then connect them in new vCenter and add to imported vDS
Am trying to do all the above using powercli, I was able to export and import vDS with no issues.
I was able to disconnect the host from old vCenter and add it to new vCenter
When I saw virtual switch on the esxi host it seems like it has reference of vDS from old vCenter. When I try to add to vDS on the new vCenter it works if I do it manually. But if I do it with powercli it throws back host is already added to switch. Any idea how do I do this ?
Command -->
$dest_vds = Get-VDSwitch -Location $datacenter -Server $newvc -ErrorAction Stop
$dest_vds | Add-VDSwitchVMHost -VMHost (Get-VMHost -Name $esxi -Server $newvcenter) -ErrorAction Stop
$dest_vds -> vDS on new vCenter
Error --> Add-VDSwitchVMHost : 01/21/2020 22:17:47 Add-VDSwitchVMHost VMHost 'labesxihost.labtzu.com' is already added to VDSwitch 'Lab-Fx-SWT'
Did you try removing the ESXi node temporarily from the VDS with the Remove-VDSwitchVMHost cmdlet in the source vCenter?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nope, I have some running Virtual Machines and we need this to be an live migration.
And you can't vMotion these VMs to another ESXi node for the time of the migration?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The steps I have followed to move ESXi from old vcenter to New vCenter.
1)If you have redundant NICs to pass the traffic, please remove one vmnic and add that NIC to standard switch.
#Migrating vmnic from vDS to vSS
$vmhost | Get-VirtualSwitch -name $vss_name | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $vmnic1 -Confirm:$false
2)Create pg on standard switch and migrate the VMs from vDS to standard switch
#Adding new vSS
Get-VirtualSwitch -VMHost $vmhost -Name vSwitch1 | New-VirtualPortGroup -Name vmpg_100 -VLanId 100
#Migrating management network
$mgmt_name = "Management_vLAN208"
$mgmt_vmk = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmk0"
$mgmt_pg = New-VirtualPortGroup -VirtualSwitch $vss -Name $mgmt_name -VLanId 208
$vmhost | Get-VirtualSwitch -name $vss_name | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $vmnic3 -VMHostVirtualNic $mgmt_vmk -VirtualNicPortgroup $mgmt_pg -Confirm:$false
# migration/edit of VM port group VDS to VSS
Get-vmhost $vmhost | Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq $Oldpg_100} |Set-NetworkAdapter -NetworkName $Newpg_100 -Confirm:$false
3)Remove redundant vmnic on vDS and then remove vDS switch attached to the ESXi host
#After checking no VMs on any port groups please remove redundant NICs
$vmhost | Get-VirtualSwitch -name $vss_name | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $vmnic2 -Confirm:$false
4)Disconnect the host in old vCenter and add it back the host in New vCenter.
Set-VMHost -VMHost $vmhost -state Disconnected
5)Attach the distributed switch to the ESXi host in New vcenter and add only one vmnic
$gz_vds = Get-VDSwitch "dvSwitch-MCOM-Ops2-V5-GreenZone"
$gz_vds | Add-VDSwitchVMHost -VMHost $vmhost
#migrating vSS to vDS vmnic0
$gz_vmhostNetworkAdapter = get-vmhost -Name $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic0
$gz_vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $gz_vmhostNetworkAdapter
6)Move VMs to new vCenter vDS and once the migration is done, delete the vmnic in vSS and add back to vDS.
Get-vmhost $vmhost | Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq $Oldpg_100} |Set-NetworkAdapter -NetworkName $Newpg_100 -Confirm:$false