profile for Gajendra D Ambi on Stack Exchange, a network of free, community-driven Q&A sites

Thursday, August 4, 2016

Remove Zombie portgroups on your Esxi hosts



Here is the scenario
PS C:\windows\system39> get-virtualportgroup

Name                      Key                            VLanId PortBinding NumPorts
----                      ---                            ------ ----------- --------
BDL-vbxx-PXE-BUILD       key-vim.host.PortGroup-BDL-... 3908                      
My-my-pg          key-vim.host.PortGroup-Vblo... 1098                      
                          key-vim.host.PortGroup-        0                         
BDL-99-Vmotion         key-vim.host.PortGroup-BDL-... 3906                      
My-my-pg_vmk      key-vim.host.PortGroup-Vblo... 1098                      
BDL-99-NAS             key-vim.host.PortGroup-BDL-... 3907                      
BDL-99-MGMT            key-vim.host.PortGroup-BDL-... 1193                      
BDL-99-MGMT_vmk        key-vim.host.PortGroup-BDL-... 1193   

Now here you have a problem where the 3rd portgorup has no name and thus cannot be delted from the GUI but
PS C:\windows\system39> $pg = get-virtualportgroup | where vlanid -EQ 0
$pg

Name                      Key                            VLanId PortBinding NumPorts
----                      ---                            ------ ----------- --------
                          key-vim.host.PortGroup-        0    

the above we can do. Now let us try to remove this
PS C:\windows\system39> $pg | Remove-VirtualPortGroup -Confirm:$false
Remove-VirtualPortGroup : 4/8/9016 3:40:41 PM    Remove-VirtualPortGroup        The resource '       ' is in use.   
At line:1 char:7
+ $pg | Remove-VirtualPortGroup -Confirm:$false
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Remove-VirtualPortGroup], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveVirtualPortGroup

And it won’t let us since it says it is busy. We have seen this when there is a vmkernel in the portgroup that we are trying to delete. Let us list the vmkernels shall we…
PS C:\windows\system39> Get-VMHostNetworkAdapter

Name       Mac               DhcpEnabled IP              SubnetMask      DeviceName
----       ---               ----------- --              ----------      ----------
vmnic0     e0:0e:da:71:15:e6 False                                           vmnic0
vmnic1     e0:0e:da:71:15:e7 False                                           vmnic1
vmnic9     e0:0e:da:71:15:e8 False                                           vmnic9
vmnic3     e0:0e:da:71:15:e9 False                                           vmnic3
vmnic4     90:e9:ba:c4:04:f4 False                                           vmnic4
vmnic5     90:e9:ba:c4:04:f5 False                                           vmnic5
vmnic6     a0:36:9f:9d:b0:c0 False                                           vmnic6
vmnic7     a0:36:9f:9d:b0:c9 False                                           vmnic7
vmk0       90:e9:ba:c4:04:f4 False       10.89.98.99     955.955.954.0         vmk0
vmk8       00:50:56:6f:dd:cd False                                             vmk8
vmk9       00:50:56:6e:7b:ad False       199.168.907.99  955.955.955.0         vmk9
vmk9       00:50:56:66:d1:99 False       10.89.93.99     955.955.955.0         vmk9
vmk1       00:50:56:69:74:a8 False       199.168.906.99  955.955.955.0         vmk1

as you can see the vmk 8 is the culprit with no ip and subnet mask to it.
PS C:\windows\system39> $vmk = Get-VMHostNetworkAdapter | where Name -EQ vmk8
$vmk

Name       Mac               DhcpEnabled IP              SubnetMask      DeviceName
----       ---               ----------- --              ----------      ----------
vmk8       00:50:56:6f:dd:cd False                                             vmk8


so now we have got that vmk too. Let us remove that sucker first.
PS C:\windows\system39> $pg = get-virtualportgroup | where vlanid -EQ 0
$vmk = Get-VMHostNetworkAdapter | where Name -EQ vmk8
Remove-VMHostNetworkAdapter -Nic $vmk -confirm:$false

PS C:\windows\system39> 
No errors but lets check anyway
PS C:\windows\system39> Get-VMHostNetworkAdapter

Name       Mac               DhcpEnabled IP              SubnetMask      DeviceName
----       ---               ----------- --              ----------      ----------
vmnic0     e0:0e:da:71:15:e6 False                                           vmnic0
vmnic1     e0:0e:da:71:15:e7 False                                           vmnic1
vmnic9     e0:0e:da:71:15:e8 False                                           vmnic9
vmnic3     e0:0e:da:71:15:e9 False                                           vmnic3
vmnic4     90:e9:ba:c4:04:f4 False                                           vmnic4
vmnic5     90:e9:ba:c4:04:f5 False                                           vmnic5
vmnic6     a0:36:9f:9d:b0:c0 False                                           vmnic6
vmnic7     a0:36:9f:9d:b0:c9 False                                           vmnic7
vmk0       90:e9:ba:c4:04:f4 False       10.89.98.99     955.955.954.0         vmk0
vmk9       00:50:56:6e:7b:ad False       199.168.907.99  955.955.955.0         vmk9
vmk9       00:50:56:66:d1:99 False       10.89.93.99     955.955.955.0         vmk9
vmk1       00:50:56:69:74:a8 False       199.168.906.99  955.955.955.0         vmk1

vmk8 has been officially sent to hell.
Lets remove the house (portgroup) where it was staying, shall we?
PS C:\windows\system39> $pg = get-virtualportgroup | where vlanid -EQ 0
$pg | Remove-VirtualPortGroup -Confirm:$false

PS C:\windows\system39> get-virtualportgroup

Name                      Key                            VLanId PortBinding NumPorts
----                      ---                            ------ ----------- --------
BDL-1000               key-vim.host.PortGroup-CPL-... 3908                      
My-my-pg               key-vim.host.PortGroup-Vblo... 1098                      
CPL-99-Vmotion         key-vim.host.PortGroup-CPL-... 3906                      
My-my-pg_vmk           key-vim.host.PortGroup-Vblo... 1098                      
CPL-99-NAS             key-vim.host.PortGroup-CPL-... 3907                      
CPL-99-MGMT            key-vim.host.PortGroup-CPL-... 1193                      
CPL-99-MGMT_vmk        key-vim.host.PortGroup-CPL-... 1193   

All is well and good.

No comments:

Post a Comment