Hello all,
I need to remove the vmware portgroup from a vswitch without touching the other portgroups. The vmware portgroup is later on added to a new vSwitch.
When I run the command I get an error that the resource is in use.
The host is:
Any suggestions?
Thanks
/Björn
Hi.
Thanks for posting this question, I too had the need to complete the same task today.
I've posted my final script which I've found to work in ESX v4.1 Update 1.
It's basic and annotated for the community to work with in their scripts.
#Connect to serverWrite-Host "Connecting to server"Connect-VIServer -Server 192.168.1.199 -User root -Password Pa55w0rd | Out-NullWrite-Host "Retrieving server details"#Retrieve the host details$esxhost = Get-VMHost -Name "192.168.1.199"#Set Port Group to look for (case sensitive)$PGName = "vmotion"Write-Host "Looking for vmk NIC assigned to vmotion"#Look for the vmk NIC for vmotion$vmkNic = Get-VMHostNetworkAdapter -VMHost $esxhost | where {$_.PortgroupName -eq $PGName}Write-Host "Deleting vmk NIC assigned to vmotion"#Remove the vmk NIC for vmotion, once removed it becomes a normal Port Group from a VMKernel one.Remove-VMHostNetworkAdapter -Nic $vmkNic -Confirm:$false |Out-Null#Set a couple variables$redundantpg = "vmotion"Write-Host "Removing vmotion Port Group"#Retrieve the vmotion Port Group details$defaultvpg = Get-VirtualPortGroup -Name $redundantpg#Remove the vmotion Port GroupRemove-VirtualPortGroup -VirtualPortGroup $defaultvpg -Confirm:$false |Out-NullWrite-Host "Disconnecting from server"#Disconnect from the serverDisconnect-VIServer -Server 192.168.1.199 -Confirm:$false
What I did notice is I needed to use the -VirtualPortGroup switch instead of -name for Remove-VirtualPortGroup
Regards,
Darren
@dawoo
Most likely the port group can not be removed because there is still a VMKernel port configured for vMotion.
Try removing the vMotion vmk before removing the port group. Remove-VMHostNetworkAdapter
For a vmKernel portgroup you first have to remove the virtualNic from the portgroup.
Something like this
$pgName = "vMotion"
$vNic = Get-VMHostNetworkAdapter -VMHost $esx | where {$_.PortgroupName -eq $pgName} Remove-VMHostNetworkAdapter -Nic $vNic
Remove-VirtualPortgroup -Name $pgName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello, and thank you for your reply.
I ran the script you so kindly gave me. What happened is that the vmk got converted to a Virtual Machine Port Group and generated and error below:
I've played around with removing the portgroup (still called vmotion) but without success.
Appreciate any help.
THanks
/Björn
What do the following return now ?
$pgName = "vMotion"
Get-VMHostNetworkAdapter -VMHost $esx | where {$_.PortgroupName -eq $pgName} | Select *
Get-VirtualPortgroup -Name $pgName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I got:
Get-VMHostNetworkAdapter : Cannot validate argument on parameter 'VMHost'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.At D:\AdminTools\powershell\RemoveVMK.ps1:7 char:33+ Get-VMHostNetworkAdapter -VMHost <<<< $esx | where {$_.PortgroupName -eq $pgName} | Select *+ CategoryInfo : InvalidData: (:) [Get-VMHostNetworkAdapter], ParameterBindingValidationException+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetVMHostNetworkAdapterBut if I added a * after esx it appeared to work
Get-VMHostNetworkAdapter -VMHost $esx*This is the output
VMotionEnabled : True
FaultToleranceLoggingEnabled : False
IPv6 :
AutomaticIPv6 :
IPv6ThroughDhcp :
IPv6Enabled :
Mtu : 1500
PortGroupName : vmotion
Id : key-vim.host.VirtualNic-vmk1
VMHostId : HostSystem-ha-host
VMHost : esx-dr-01
VMHostUid : /VIServer=root@esx-dr-01:443/VMHost=HostSystem-ha-host/
DeviceName : vmk1
Mac : 00:50:56:78:90:69
DhcpEnabled : False
IP : 10.0.0.205
SubnetMask : 255.255.0.0
Name : vmk1
ExtensionData : VMware.Vim.HostVirtualNic
Name : vmotion
VirtualSwitchId : key-vim.host.VirtualSwitch-vSwitch0
VirtualSwitchUid : /VIServer=root@esx-dr-01:443/VMHost=HostSystem-ha-host/VirtualSwitch=key-vim.host.VirtualSwitch-vSwitch0/
VirtualSwitch : vSwitch0
Key : key-vim.host.PortGroup-vmotion
Port : {key-vim.host.PortGroup.Port-16777221}
VLanId : 5
VirtualSwitchName : vSwitch0
VMHostId : HostSystem-ha-host
VMHostUid : /VIServer=root@esx-dr-01:443/VMHost=HostSystem-ha-host/
ExtensionData : VMware.Vim.HostPortGroup
The $esx variable should hold the object returned by
$esx = Get-VMHost -Name <the-name-of-your-ESX-server>
That's probably the reason why my script didn't work either
From the output I can see that the portgroup still has the virtualnic vmk1 connected to it.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Oki, thanks.
Right... I should have figurered out the $esx variable.
I also got it to identify the portgroup but I still get same error. I dont know what to do unfortunately.
Remove-VirtualPortGroup : A parameter cannot be found that matches parameter name 'Name'.At line:1 char:30+ Remove-VirtualPortgroup -Name <<<< $pgName+ CategoryInfo : InvalidArgument: (:) [Remove-VirtualPortGroup], ParameterBindingException+ FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveVirtualPortGroupThis is what the script looks like now:
$esx = Get-VMHost -Name "esx-dr-01"
$pgName = "vmotion"
Get-VMHostNetworkAdapter -VMHost $esx | where {$_.PortgroupName -eq $pgName} | Select *
Get-VirtualPortgroup -Name $pgName
Remove-VMHostNetworkAdapter -Nic $vNic
Remove-VirtualPortgroup -Name $pgName
Any help is appreciated.
Thanks
Perhaps it's just a typo, but the script is missing the assignment to the $vNic variable.
$esx = Get-VMHost -Name "esx-dr-01"
$pgName = "vmotion"
$vNic = Get-VMHostNetworkAdapter -VMHost $esx | where {$_.PortgroupName -eq $pgName}
Remove-VMHostNetworkAdapter -Nic $vNic
Remove-VirtualPortgroup -Name $pgName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi.
Thanks for posting this question, I too had the need to complete the same task today.
I've posted my final script which I've found to work in ESX v4.1 Update 1.
It's basic and annotated for the community to work with in their scripts.
#Connect to serverWrite-Host "Connecting to server"Connect-VIServer -Server 192.168.1.199 -User root -Password Pa55w0rd | Out-NullWrite-Host "Retrieving server details"#Retrieve the host details$esxhost = Get-VMHost -Name "192.168.1.199"#Set Port Group to look for (case sensitive)$PGName = "vmotion"Write-Host "Looking for vmk NIC assigned to vmotion"#Look for the vmk NIC for vmotion$vmkNic = Get-VMHostNetworkAdapter -VMHost $esxhost | where {$_.PortgroupName -eq $PGName}Write-Host "Deleting vmk NIC assigned to vmotion"#Remove the vmk NIC for vmotion, once removed it becomes a normal Port Group from a VMKernel one.Remove-VMHostNetworkAdapter -Nic $vmkNic -Confirm:$false |Out-Null#Set a couple variables$redundantpg = "vmotion"Write-Host "Removing vmotion Port Group"#Retrieve the vmotion Port Group details$defaultvpg = Get-VirtualPortGroup -Name $redundantpg#Remove the vmotion Port GroupRemove-VirtualPortGroup -VirtualPortGroup $defaultvpg -Confirm:$false |Out-NullWrite-Host "Disconnecting from server"#Disconnect from the serverDisconnect-VIServer -Server 192.168.1.199 -Confirm:$false
What I did notice is I needed to use the -VirtualPortGroup switch instead of -name for Remove-VirtualPortGroup
Regards,
Darren
@dawoo
Late answer, but you are of course right! Thank you!
Nice script, it worked. Thanks!
This is a very old post but was the first one I found when search for this.
No one seemed to find the real issue