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 10.170.220.50 -EndRange 10.170.220.253 -SubnetMask 255.255.255.0 -State Active -LeaseDuration 1.00:00:00  
Add-DhcpServerv4Scope -ComputerName staging-dc01 -Name LiveMigration -StartRange 10.170.221.1 -EndRange 10.170.221.253 -SubnetMask 255.255.255.0 -State Active -LeaseDuration 10.00:00:00  
Add-DhcpServerv4Scope -ComputerName staging-dc01 -Name Cluster -StartRange 10.170.222.1 -EndRange 10.170.222.253 -SubnetMask 255.255.255.0 -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 10.170.220.0 -DnsDomain gwpcstaging.com -Router 10.170.220.254 -DnsServer 10.170.220.21,10.170.220.22  
# Add DHCP Failover Relationship 
Add-DhcpServerv4Failover -ComputerName staging-dc01 –Name staging-dc01-TO-staging-dc02 -ScopeId 10.170.220.0,10.170.221.0,10.170.222.0 –PartnerServer staging-dc02.gwpcstaging.com  

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.

© 2017. All Rights Reserved.