Home > Blogs > VMware PowerCLI Blog


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)


    }

}

This entry was posted in Advanced and tagged , , , on by .
Brian Graf

About Brian Graf

Brian Graf is a well-known VMware evangelist in the IT community. Over the past 5 years, Brian has done Technical Marketing for PowerCLI Automation and ESXi Lifecycle, Product Management of vCenter Distributed Resource Management features (DRS & HA), and is currently working as a Technical Marketing Manager for VMware Cloud on AWS. Brian is a co-author of the PowerCLI Deep Dive 2nd edition book. He has helped develop VMware certification courses and exams and presents around the world at VMware User Conferences, AWS Summits, Interop, as well as other industry Conferences. Brian is also a Microsoft MVP.

One thought on “Removing IP Pools Using PowerCLI

  1. Pingback: Technology Short Take #41 - blog.scottlowe.org - The weblog of an IT pro specializing in virtualization, networking, cloud, servers, & Macs

Leave a Reply

Your email address will not be published. Required fields are marked *

*