VMware Cloud Community
erickmiller
Enthusiast
Enthusiast
Jump to solution

Removing a Port Group?

Hi,

I saw the discussion about the AddPortGroup function for adding port groups to a virtual switch, but haven't seen anything about removing a port group from a virtual switch. Is there any way of doing this with the vi toolkit?

Thanks!

Eric K. Miller, Genesis Hosting Solutions, LLC

- Lease part of our ESX cluster!

Eric K. Miller, Genesis Hosting Solutions, LLC http://www.genesishosting.com/ - Lease part of our ESX cluster!
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Sure, the following script removes a portgroup from all ESX servers.

If you want to remove the portgroup from a specific ESX server you can add for example a -Name parameter to the Get-VMHost cmdlet.

$MyPortGroupName = "Internal"

Get-VMHost  | %{Get-View (Get-View $_.ID).configmanager.networkSystem} | %{
  $_.RemovePortGroup($MyPortGroupName)
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Sure, the following script removes a portgroup from all ESX servers.

If you want to remove the portgroup from a specific ESX server you can add for example a -Name parameter to the Get-VMHost cmdlet.

$MyPortGroupName = "Internal"

Get-VMHost  | %{Get-View (Get-View $_.ID).configmanager.networkSystem} | %{
  $_.RemovePortGroup($MyPortGroupName)
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
erickmiller
Enthusiast
Enthusiast
Jump to solution

Worked perfectly!! Thanks!

Eric K. Miller, Genesis Hosting Solutions, LLC

- Lease part of our ESX cluster!

Eric K. Miller, Genesis Hosting Solutions, LLC http://www.genesishosting.com/ - Lease part of our ESX cluster!
0 Kudos
dzi-icoma
Contributor
Contributor
Jump to solution

You could use the attached script with PowerScripter with right click on a host within VI client and chosing the menu item of the script. This script opens a Select Box for deleting portgroups.You can select a host, multiple hosts, a cluster or a datacenter an run the script against for deleting the portgroups anywhere.

PowerScripter - customize VI client or VirtualCenter

www.powerscripter.net

PowerScripter - customize VI client or VirtualCenter http://powerscripter.net
0 Kudos
iHunger
Contributor
Contributor
Jump to solution

Just wanted to update the information about PowerScripter - it is now  being developed by Devfarm Software and has been rebranded as PowerVI.   You can get more information at: http://powerwf.com/products/powerscripter.aspx

0 Kudos
sushilkm
Enthusiast
Enthusiast
Jump to solution

LucD

Much water have flown down the bridge since this 2008 post so thought to recheck Smiley Happy

I intend to use below code to Mass delete DVS port groups from a VDS starting with "vxw" and have adapted the below code . V center version is 6.5 .

$MyPortGroupName = "Internal"

Get-VMHost  | %{Get-View (Get-View $_.ID).configmanager.networkSystem} | %{

  $_.RemovePortGroup($MyPortGroupName)

}

to

$MyPortGroupName = "*vxw*"

Get-VMHost  | %{Get-View (Get-View $_.ID).configmanager.networkSystem} | %{

  $_.RemovePortGroup($MyPortGroupName)

}

I was wondering if above will work as i m trying to use wild character * in Above example. I was trying to use these wild characters in Get-virtualswitch command and they seems to be working on their own good will .

Kinldy advice if there is a alternate way to delete port groups enmass. All are VM port groups.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That will not work, the RemovePortgroup method does not support name masking.

But you could do something like this

foreach($vdp in (Get-VDPortgroup -Name "*vxw*" | Select -ExpandProperty Name)){

  Get-VMHost | %{Get-View (Get-View $_.ID).configmanager.networkSystem} | %{

   $_.RemovePortGroup($vdp)

  }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference