Building your DHCP Configuration with PowerShell

How about 7 Lines of PowerShell to Deploy a Robust DHCP Infrastructure?

This is going to be a quick post! I am tired of building up and tearing down labs in my environment and constantly running around addressing all of the servers that make up my lab. Today I had to deploy a number of Hyper-V hosts which of course require multiple interfaces on different networks and I decided to implement DHCP to address my Hyper-V hosts this go around. Of course if you implement DHCP for something like this it needs to be robust and highly available.

This was the first chance I got to play with DHCP failover which came about in Windows Server 2012. I have basically deployed 2 DHCP servers which are running on my domain controllers. Below is all of the PowerShell code I used today to deploy my DHCP configuration to my already deployed servers.

# Add DHCP Role to the designated DHCP servers
Invoke-Command -ComputerName staging-dc01,staging-dc02 -ScriptBlock { Add-WindowsFeature -Name DHCP -IncludeManagementTools }
# Authorize DHCP Servers in AD
Invoke-Command -ComputerName staging-dc01,staging-dc02 -ScriptBlock { Add-DhcpServerInDC }
# Add DHCP Scopes 
Add-DhcpServerv4Scope -ComputerName staging-dc01 -Name Management -StartRange -EndRange -SubnetMask -State Active -LeaseDuration 1.00:00:00 
Add-DhcpServerv4Scope -ComputerName staging-dc01 -Name LiveMigration -StartRange -EndRange -SubnetMask -State Active -LeaseDuration 10.00:00:00 
Add-DhcpServerv4Scope -ComputerName staging-dc01 -Name Cluster -StartRange -EndRange -SubnetMask -State Active -LeaseDuration 10.00:00:00 
# Set options on DHCP scopes (only needed on MGMT in my case) 
Set-DhcpServerv4OptionValue -ComputerName staging-dc01 -ScopeId -DnsDomain -Router -DnsServer, 
# Add DHCP Failover Relationship 
Add-DhcpServerv4Failover -ComputerName staging-dc01 –Name staging-dc01-TO-staging-dc02 -ScopeId,, –PartnerServer

So far this is running like a champ! I am going to try out running my Hyper-V servers completely on DHCP for a bit and see how this goes.