7 Best Powershell Scripts to manage DHCP

Getting IP from the DHCP scope looks very easy but you know it is very hard when it comes to the checking the health of each scope whether it is full or do we need to create any superscope. If you are a Server administrator you really know what I am talking about and yes it is painful when clients complains about they are not getting any IP and voila you see in your scope everything looks empty.

Making a DHCP server or scope to update the DNS dynamically on multiple DHCP servers is not easy task and knowing the exact scope where it lies in your domain is much a hardship. Via Powershellguru my aim was always to deliver the easy solution to the problems which I have faced generally in my production environment. Below are some books you can refer about DHCP and it’s working and about Powershell. I hope you like it and most of the freeware always reside in Wikipedia and Microsoft.

Useful Powershell commands for DHCP

Add an object for the DHCP server service

				
					Add-DhcpServerInDC -DnsName "dhcp.xyz.com"
				
			

Back up the DHCP server database

				
					Backup-DhcpServer -ComputerName "dhcp.xyz.com" -Path "%systemroot\dhcp\backup"
				
			

Export all DHCP configurations

				
					Export-DhcpServer -ComputerName "dhcp.xyz.com" -File "path\config.xml"
				
			

Get all active leases in a scope

				
					Get-DhcpServerv4Lease -ComputerName "dhcp.xyz.com" -ScopeId IP
				
			

Get properties for a policy by name

				
					Get-DhcpServerv4Policy -ComputerName "dhcp.xyz.com" -Name "policyname"
				
			

Powershell Scripts for DHCP

DHCP Failover

Creating a failover usually is on a better side. All the hits won’t be coming on a particular DHCP server rather will be managed by 2 servers. 

How it works

This script will create a failover between 2 DHCP servers for which we have to mention and the scope as well. Later the script will create a failover between the both DHCP servers.

Probable outcome

After the script runs just check the failover is working fine or not. The hits should be coming on both the servers.

Download

You can download the script from below.

DHCP Backup

Having a backup of DHCP is a boon when you don’t have the failover configured in your environment. You can restore the backup to the last time of backup and everything will be back online.

How it works

The path is already set and we need to run the script on a dhcp server and that’s, it will create a backup of dhcp.

Problem outcome

The script reduces manual effort which we do from GUI and creates the backup in the provided location.

Download

You can download the script from below.

DNS Dynamic Update

Dynamic assignment of IP is one of the role of DHCP and it is not turned on automatically and needs to done by GUI but why to rush to the GUI when you can do it via Powershell.

How it works

This script will enable the DNS Dynamic Update settings for a scope or to all the scopes as per the requirement.

Probable Outcome

Dynamic updates will be enabled and host resolution will be corrected for the machines that are DHCP enabled.

Download

You can download the script via the highlighted link.

Configure Lease Duration

The lease duration is always set to 8 days as per Microsoft. But in practical we change it for scopes but why to do using GUI when we can create a script.

How it works

For a provided scope you can set the lease duration using this script.

Probable Outcome

The lease duration will be set and we can test it on any machine if required or else it will be working as expected. 

Download

You can download the script via the highlighted link.

DHCP Health check

One of the most practical scripts which let us know about the scopes, subnet, scope disabled if any etc. A must unique and downloadable scripts of all.

How it works

The script will scan through the scopes of the give servers ad send results via mail.

Probable Outcome

We will receive the details about the scope which is good to know in case if any one of them is about to fill.

Download

You can download the script via the highlighted link.

Multiple DHCP scope Creation

Need to create multiple DHCP scopes well then this script is for just you, do check it out on the basis of your requirement.

How it works

It requires input ad we need to provide as the notes, so that it creates the scopes in a jiffy.

Probable Outcome

All the provided inputs will be used to create multiple DHCP scopes it is one kind of handy scripts.

Download

You can download the script via the highlighted link.

Router details from multiple scopes

Ever thought about getting the router IP details from multiple scopes, well Powershell does this all for us created a script for that a life saver though.

How it works

Provide the scope ID details using Get-DhcpServerv4Scope  in a text format and it will fetch the Router IP from the given scopes.

Probable Outcome

Results will be fetched in a csv format where with scope ID the Router IP details will be fetched.

Download

You can download the script via the highlighted link.

close
blank

DON’T MISS A POST

Keep up to date with PowershellGuru

SSShhhhhhh.........We don’t spam!

Powershell Blogs
7 Best Powershell scripts to manage DHCP
Copy link