PowerShell GUI : Releasing Multiple Stale IP's from DHCP Scope at once.
SCENARIO : Multiple stale IP Addresses for clients no longer connected to the network are occupying the DHCP scope and Clients aren’t able to request free IP Leases.
POSSIBLE SOLUTIONS :
- Reduce the lease duration to something below than Default 8 Days, so that stale IP’s could be auto deleted
- Increasing the DHCP Scope Size to accommodate new client requests.
- Delete IP addresses that are disconnected from network and free some Scope IP Addresses
We would be focussing on the Third solution here in our script, because it sounds more feasible, quick and effective.
IDEA : Use the DHCPServer Powershell module to query the IP Addresses of a Scope and check if they are responding to Ping requests, if not delete those IP’s from Scope to free some space.
HOW IT WORKS :
- Import the DHCPServer PowerShell module to your machine from a Windows 2012 server with DHCP role installed on it, which by default has the DHCP Module.
NOTE : Please note this DHCP server is from which we’re importing the Powershell Module onto our machine, not the DHCP server from which IP addresses would be deleted.
- When you run the script the it will prompt you for DHCPServer to pull the powreshell modules from.
- You will be prompted for your Domain Credential to access the server to import DHCP module.
- Once you feed in your domain credentials and hit enter it will download the Powershell module onto your machine from the Win 2012 DHCP server you mentioned in above step. Using the Import-Mdolue Cmdlet like below –
Import-Module -PSSession (New-PSSession -ComputerName $DHCPServer -Credential Get-Credential ) -Name dhcpserver
- Once download is complete, user will be prompted for Information like target DHCP Server, Scope ID and Count of IP’s to be deleted.
- Click OK, to proceed
- A Summary form will appear, which will summarize the details you mentioned in Previous step and the script will check for stale IP Addresses from the DHCP Scope
- Once stale IP’s are identified, they would be listed and you will be prompted to Choose or decline the deletion of these IP’s from the scope.
- You can Due diligently check IP’s and Host names to be deleted from the scope and click OK Button.
- Stale IP’s will be deleted at once and a log file would be generated like in the below screenshots.
GET THE SCRIPT : Click here to go to my GitHub gist to get the code.
Hope you find it useful. Happy Reading Fellas 🙂