So, I'm trying to automate removing a host from vcenter, and need to move the vmks off the vDS to a vSS. Started with William Lam's very good script here:
https://williamlam.com/2013/11/automate-reverse-migrating-from-vsphere.html
But it was failing. So I broke out the migration of each vmk, one step at a time. vmk1 & 2 migrate just fine. vmk0 migrates just fine in the gui. But fails every time via PowerCLI - network change, can't talk to host, rolled back change.
My version of William's script:
#####rollback to std switch so host can be removed
#add std switch
$vss = New-VirtualSwitch -VMHost $vmhost -Name "vSwitch0"
$vmnic0 = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmnic0" -Physical
$vmnic1 = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmnic1" -Physical
$pnic_array = @($vmnic0,$vmnic1)
#add std portgroups
$mgmt_pg = New-VirtualPortGroup -VirtualSwitch $vss -Name "Management Network"
$vmotion_pg = New-VirtualPortGroup -VirtualSwitch $vss -Name "vMotion"
$backup_pg = New-VirtualPortGroup -VirtualSwitch $vss -Name "Backup"
$pg_array = @($mgmt_pg,$vmotion_pg,$backup_pg)
#add vmk interfaces
$mgmt_vmk = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmk0"
$vmotion_vmk = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmk1"
$backup_vmk = Get-VMHostNetworkAdapter -VMHost $vmhost -Name "vmk2"
$vmk_array = @($mgmt_vmk,$vmotion_vmk,$backup_vmk)
#move vmnic1 and vmk0,1,2 to std switch
# maybe not needed?? Remove-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmnic1 -Confirm:$false
Add-VirtualSwitchPhysicalNetworkAdapter -VirtualSwitch $vss -VMHostPhysicalNic $vmnic1 -VMHostVirtualNic $backup_vmk -VirtualNicPortgroup $backup_pg -Confirm:$false
Add-VirtualSwitchPhysicalNetworkAdapter -VirtualSwitch $vss -VMHostPhysicalNic $vmnic1 -VMHostVirtualNic $vmotion_vmk -VirtualNicPortgroup $vmotion_pg -Confirm:$false
#this fails
Add-VirtualSwitchPhysicalNetworkAdapter -VirtualSwitch $vss -VMHostPhysicalNic $vmnic1 -VMHostVirtualNic $mgmt_vmk -VirtualNicPortgroup $mgmt_pg -Confirm:$false
#this fails
Add-VirtualSwitchPhysicalNetworkAdapter -VirtualSwitch $vss -VMHostPhysicalNic $pnic_array -VMHostVirtualNic $vmk_array -VirtualNicPortgroup $pg_array -Confirm:$false
#Remove VDSs
foreach ($vdswitch in $vdswitches) {
Remove-VDSwitchVMHost -VDSwitch $vdswitch -VMHost $vmHost -confirm:$false
}
remove-vmhost $fullhostname -Confirm:$false
Every time vmk0 is included in the migration, it fails.
$networkid = $VMHost.ExtenSionData.Configmanager.NetworkSystem
$interface = "vmk0"
$nic = New-Object VMware.Vim.HostVirtualNicSpec
$nic.portgroup = "Management Network"
$_this = Get-View -Id $networkid
$_this.UpdateVirtualNic($Interface, $nic)
And it fails exactly the same way - "An error occurred while communicating with the remote host. Network configuration change disconnected the host 'hostname.localdom.com' from vCenter server and has been rolled back"
Feels like I'm missing something simple, but I've been beating my head against it for 2 days now & can't see anything.
Appreciate any pointers where I might be missing something.