Ray,
Not exactly what you are doing but might give you an example of how to move a host. THis script I created will migrate our 2 interfaces from a DVswitch back to a standard and then reregister at a new Vcenter.
This will put host in maint mode, but you could remove that part and do a disconnect/remove instead after you've done your migrate VM's to standard switch. I do hardcode the 2 vcenter names in a couple spots in the script where you would want to modify for your 2 vcenters. So you might have to tailor it to your needs.
You could do a txt list with all the host names example:
$hosts = get-content hostlist.txt
foreach ($vmhost in $hosts) {
Migrate_Host -VMHost $VMhost -VDSwitch "switchname"
}
functionMigrate_Host {param ( [Parameter(Mandatory=$true)][string]$VMHost, [Parameter(Mandatory=$true)][string]$VDSwitch)
#Get Credentials to pass to Connect$credential=Get-Credential -Message "Please enter your credentials"#Connect to old VcenterConnect-VIServervcenter01-Credential$credential#Set host into maintenance modeSet-VMHost-VMHost$VMHost-StateMaintenance-Evacuate-Confirm:$false#Get VMhost object data$VMHostobj=Get-VMHost$VMHost#Remove Vmnic1 adapter from VDS$VMhostObj | Get-VMHostNetworkAdapter-Physical-Namevmnic1 | Remove-VDSwitchPhysicalNetworkAdapter-Confirm:$false#Wait till it is removedStart-Sleep-S5#Add Physical nic to Standard SwitchGet-VirtualSwitch-VMhost$VMHost-name"vSwitch0" | Set-VirtualSwitch-Nic"vmnic1"-Confirm:$false#Set network ID object for Standard Switch$networkid=$VMHostObj.ExtenSionData.Configmanager.NetworkSystem# ------- AddPortGroup ------- for VMotion$portgrp=New-ObjectVMware.Vim.HostPortGroupSpec$portgrp.name ="VMotion"$portgrp.vlanId =3721$portgrp.vswitchName ="vSwitch0"$portgrp.policy =New-ObjectVMware.Vim.HostNetworkPolicy$_this=Get-View-Id$networkid$_this.AddPortGroup($portgrp)# ------- UpdateVirtualNic ------- for Vmotion$nic=New-ObjectVMware.Vim.HostVirtualNicSpec$nic.portgroup ="VMotion"$_this=Get-View-Id$networkid$_this.UpdateVirtualNic("vmk1", $nic)# ------- AddPortGroup ------- for Management$portgrp=New-ObjectVMware.Vim.HostPortGroupSpec$portgrp.name ="Management"$portgrp.vlanId =0$portgrp.vswitchName ="vSwitch0"$portgrp.policy =New-ObjectVMware.Vim.HostNetworkPolicy$_this=Get-View-Id$networkid$_this.AddPortGroup($portgrp)# ------- UpdateVirtualNic ------- for Management$nic=New-ObjectVMware.Vim.HostVirtualNicSpec$nic.portgroup ="Management"$_this=Get-View-Id$networkid$_this.UpdateVirtualNic("vmk0", $nic)#Remove 2nd nic from the VDS$VMhostObj | Get-VMHostNetworkAdapter-Physical-Namevmnic0 | Remove-VDSwitchPhysicalNetworkAdapter-Confirm:$falseStart-Sleep-s5#Move both interfaces to standard switchGet-VirtualSwitch-VMHost$VMHost-name"vSwitch0" | Set-VirtualSwitch-Nic"vmnic0","vmnic1"-Confirm:$false#Remove host from VDswitchGet-VDSwitch | Where {$_.Name -eq$VDSwitch} | Remove-VDSwitchVMHost-VMhost$VMHost-Confirm:$false#If remove from VDS successful Remove host from Vcenterif ($?) { Start-Sleep-s5 Remove-VMHost-VMHost$VMHost-Confirm:$false Disconnect-VIServervcenter01-Confirm:$false Start-Sleep-s5#Connect to new Vcenter and add host to cluster Connect-VIServer vcenter02-Credential$credential #add transport host Add-VMHost-Name$VMHost-Location"Cluster1"-Userroot-Password"pass"-Force-Confirm:$false}else {exit
}
}