Advanced

Removing IP Pools Using PowerCLI

I recently had the need to create many IP Pools (also known as Network Protocol Profiles) for some projects I have been working on. I was able to flip through my copy of  “VMware vSphere PowerCLI Reference” and leverage a script on creating IP Pools. Not only did I need a way to create IP Pools using PowerCLI, I also needed a way to remove them as well. A quick Google search didn’t return any results on the topic so I went ahead and created a simple function that allows the user to remove them.

As you can see I currently have two pools in my virtual Data Center “SDT”

IP_Pool_View

The function requires the user to know the name of the virtual Data Center that the IP Pool is located in, and the name of the IP Pool. After the function is added into the PowerCLI session, it can be called by typing ‘Remove-IPPool <vDC Name> <IP Pool Name>’

Remove-IPPool

You will notice the task will appear in the “Recent Tasks” window once the function has run. If you are looking at the Network Protocol Profiles you will need to refresh the window to see the changes visually.

Remove-IPPool-task

The function is found below. You may also CLICK HERE to download the script in a .zip

Function Remove-IPPool {
<#
.Synopsis
This function will remove IP-Pools from vCenter
.Description
This function will remove IP-Pools from vCenter based on the inputs provided
.Example
Assuming my datacenter was ‘westwing’ and my IPPool was ‘IPPool1’
remove-ippool westwing IPPool1
.Notes
Author: Brian Graf
Role: Technical Marketing Engineer, VMware
Last Edited: 05/01/2014
 #>

     [cmdletbinding()]
Param (
[Parameter(ValueFromPipeline = $true, valuefrompipelinebypropertyname = $true)]
[String]$Datacenter,
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[String]$PoolName
)

Process {
$dc = (Get-datacenter $Datacenter)
$dcenter = New-Object VMware.Vim.ManagedObjectReference
$dcenter.type = $dc.ExtensionData.moref.type
$dcenter.Value = $dc.ExtensionData.moref.value

    $IPPoolManager = Get-View -Id ‘IpPoolManager’
$SelectedPool = ($IPPoolManager.QueryIpPools($dc.ID) | Where-Object { $_.Name -like $PoolName })


    $IPPool = Get-View -Id ‘IpPoolManager-IpPoolManager’
$IPPool.DestroyIpPool($dcenter, $SelectedPool.id, $true)


    }

}