VMware Cloud Community
BjornJohansson
Enthusiast
Enthusiast
Jump to solution

Cannot remove vmotion portgroup - "resource in use"

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:

  • ESXi 4.1 U1
  • In maintenance mode
  • Rebooted
  • Does not contain any VMs.
  • Can be successfully removed with vSphere Client

Get-VMHost | Get-VirtualPortGroup -Name "vmotion" | Remove-VirtualPortGroup -Confirm:$false
Remove-VirtualPortGroup : 2011-08-24 17:01:11    Remove-VirtualPortGroup        The resource 'vmotion' is in use.
At line:1 char:76
+ Get-VMHost | Get-VirtualPortGroup -Name "vmotion" | Remove-VirtualPortGroup <<<<  -Confirm:$false
    + CategoryInfo          : NotSpecified: (:) [Remove-VirtualPortGroup], ResourceInUse
    + FullyQualifiedErrorId : Client20_MoServiceImpl_Invoke_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveVirtualPortGroup

Any suggestions?

Thanks

/Björn

0 Kudos
1 Solution

Accepted Solutions
dawoo
Enthusiast
Enthusiast
Jump to solution

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 server
Write-Host "Connecting to server"
Connect-VIServer -Server 192.168.1.199 -User root -Password Pa55w0rd | Out-Null
Write-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 Group
Remove-VirtualPortGroup -VirtualPortGroup $defaultvpg -Confirm:$false |Out-Null
Write-Host "Disconnecting from server"
#Disconnect from the server
Disconnect-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

10 Print "It's all about the Nerdknobs" , 20 GOTO http://blog.vmote.net/

View solution in original post

0 Kudos
12 Replies
bretti
Expert
Expert
Jump to solution

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

LucD
Leadership
Leadership
Jump to solution

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

BjornJohansson
Enthusiast
Enthusiast
Jump to solution

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:

Remove-VirtualPortGroup : A parameter cannot be found that matches parameter name 'Name'.
At D:\AdminTools\powershell\RemoveVMK.ps1:4 char:30
+ Remove-VirtualPortgroup -Name <<<<  $pgName
    + CategoryInfo          : InvalidArgument: (:) [Remove-VirtualPortGroup], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveVirtualPortGroup

I've played around with removing the portgroup (still called vmotion) but without success.

Appreciate any help.

THanks

/Björn

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
BjornJohansson
Enthusiast
Enthusiast
Jump to solution

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 c
ommand 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.GetVMHostNetworkAdapter

But 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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
BjornJohansson
Enthusiast
Enthusiast
Jump to solution

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.RemoveVirtualPortGroup

This 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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
dawoo
Enthusiast
Enthusiast
Jump to solution

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 server
Write-Host "Connecting to server"
Connect-VIServer -Server 192.168.1.199 -User root -Password Pa55w0rd | Out-Null
Write-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 Group
Remove-VirtualPortGroup -VirtualPortGroup $defaultvpg -Confirm:$false |Out-Null
Write-Host "Disconnecting from server"
#Disconnect from the server
Disconnect-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

10 Print "It's all about the Nerdknobs" , 20 GOTO http://blog.vmote.net/
0 Kudos
BjornJohansson
Enthusiast
Enthusiast
Jump to solution

Late answer, but you are of course right! Thank you! Smiley Happy

0 Kudos
BjornJohansson
Enthusiast
Enthusiast
Jump to solution

Nice script, it worked. Thanks!

0 Kudos
ChrisLeblanc
Contributor
Contributor
Jump to solution

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

#Retrieve the vmotion Port Group details
$defaultvpg = Get-VirtualPortGroup -Name $redundantpg
 
This command is broad across all vmhosts. When I ran it I noticed it had output from other hosts.
 
To correct this issue if you have already removed the nics in the portgroup is to specify the host
#Retrieve the vmotion Port Group details
$defaultvpg = Get-VirtualPortGroup -Name $redundantpg -vmhost $oldhost
0 Kudos