In Part 2, we looked at how to configure DHCP failover using the DHCP Management Console. In this part, we’ll look at how to do the same task but using PowerShell.
Server infrastructure
This test lab includes the below servers:
- Contdc01
- Contdc02
Planned configuration
Here we’ll walk through how to configure DHCP failover. Our requirements are below:
- Scope 10.0.1.0/24
- Failover mode: Load balance mode (50:50)
- Automatic failover
Prerequisites
To create a failover relationship for two standalone DHCP Servers, this requires:
- two DHCP servers
- a unique failover relationship name
- a DHCP scope on only one of the DHCP servers to configure failover for (this is because the scope will be created on the other DHCP server)
How to configure failover using PowerShell
To configure DHCP failover for our scope, 10.0.1.0, we use the Add-DhcpServerv4Failover cmdlet and specify the settings we would like. We are running this command on contdc01 which is where we already have a scope configured.
- Failover Relationship Name: contdc01-contdc02
- Partner server: contdc02
- Scope ID: 10.0.1.0
- State Switchover Interval: 1hr
- Shared Secret: Password1
Add-DhcpServerv4Failover -Name “contdc01-contdc02” -PartnerServer contdc02 -ScopeId 10.0.1.0 -StateSwitchInterval 1:00:00 -SharedSecret Password1 -Force
Once done, we can confirm that DHCP failover was configured correctly by checking that the scope exists on both servers. We use Get-DhcpServerv4Scope to do this and specify each of the server names:
Get-DhcpServerv4Scope -ComputerName contdc01
Get-DhcpServerv4Scope -ComputerName contdc02
The output shows a list of scopes on each server:
To confirm the settings, we can use Get-DhcpFailover and specify the servers in turn so we can confirm our settings are correct and that they have replicated to the other server:
Get-DhcpServerv4Failover -ComputerName contdc01
Get-DhcpServerv4Failover -ComputerName contdc02
Conclusion
In this post, we’ve looked at how to configure DHCP failover using PowerShell which is much quicker and quite easy to script.