Moving DHCP from Server to Server with Powershell

My scenario: I needed to move DHCP from server 2012 to server 2012 R2 with leases.
I wanted to do this quickly and safely. You can run all of these commands from your new DHCP server:

Install DHCP + MGMT tools on the new server.

Install-windowsfeature DHCP -includemanagementtools

Authorize the new server

Add-DhcpServerInDC

Backup the old servers DHCP in case of any eff ups.

backup-dhcpserver -computername OLDDHCPSERVER -path C:\olddhcpbackup

Then we export the DHCP configuration along with leases.

export-dhcpserver -computername OLDDHCPSERVER -file C:\dhcpexport.xml -leases

The above command exports the file to the C:\ directory of the server you ran the command on.
Since I ran the command from my new server, the file is exported from the old server to the new one.

Then we need to backup the new servers DHCP, even though there’s nothing in there (it’s required later on)

backup-dhcpserver -computername NEWDHCPSERVER -path C:\newdhcpbackup

We import the DHCP settings on the new server from the file on the oldserver, the backuppath is required.

import-dhcpserver -computername NEWDHCPSERVER C:\dhcpexport.xml -leases -backuppath C:\dhcpbackup

WARNING: the below command deactivates all DHCP scopes on the server.

invoke-command -computername OLDDHCPSERVER -scriptblock {get-dhcpserverv4scope | set-dhcpserverv4scope -state inactive}

Now check your new DHCP server for the leases + reservations along with the new activated scope. Also confirm your old DHCPSERVER’s scope is deactivated.

Leave a comment

Exit mobile version