Skip to content
Ipnoria
All guides

Migrate a Windows Server DHCP

Nothing changes on Windows until switchover day. Clients keep their address: active leases are imported, then kept up to date while both servers coexist.

  1. Take an inventory

    On the Windows server (or a workstation with the RSAT DNS and DHCP tools), as an administrator. The script only reads: it lists scopes, policies, classes and any existing DHCP failover.

    PowerShell
    Get-DhcpServerv4Scope | Select-Object ScopeId, Name, SubnetMask, StartRange, EndRange, LeaseDuration, State |
      Export-Csv "$env:TEMP\dhcp-scopes.csv" -NoTypeInformation -Encoding UTF8
  2. Export the DHCP configuration

    Scopes, ranges, exclusions, reservations and options in a single XML file.

    PowerShell
    Export-DhcpServer -ComputerName $env:COMPUTERNAME -File "$env:TEMP\dhcp-export.xml" -Force
  3. Import into the console

    In Import / AD, DHCP tab, drop dhcp-export.xml. The console shows what it will create (IPAM networks, scopes, reservations) before applying it, and takes a restore point first.

  4. Bring over active leases

    Export the leases and drop the file in the DHCP step: every client gets its address back after switchover.

    PowerShell
    Get-DhcpServerv4Scope | ForEach-Object { Get-DhcpServerv4Lease -ScopeId $_.ScopeId } |
      Select-Object IPAddress, ClientId, HostName, AddressState, @{ n = 'ExpiryUtc'; e = { $_.LeaseExpiryTime.ToUniversalTime().ToString('s') } } |
      Export-Csv "$env:TEMP\dhcp-leases.csv" -NoTypeInformation -Encoding UTF8
  5. Coexist as long as needed

    While Windows still serves clients, a scheduled task can push leases to the console every 5 minutes with an API token (operator role). The full script, with console certificate pinning, is shown on the Import / AD page.

  6. Switch over

    Disable the Windows scopes (the list is kept for rollback), then point the DHCP relays (ip helper-address) to the real addresses of both cluster data nodes.

    This script changes the Windows server.

    PowerShell
    $ids = Get-DhcpServerv4Scope | Where-Object State -eq 'Active' | Select-Object -ExpandProperty ScopeId
    $ids | ForEach-Object { $_.IPAddressToString } | Out-File "$env:TEMP\scopes-actives.txt"
    $ids | ForEach-Object { Set-DhcpServerv4Scope -ScopeId $_ -State InActive }
  7. Roll back if needed

    Re-enable the scopes listed in the previous step, then point the DHCP relays back to Windows.

    PowerShell
    Get-Content "$env:TEMP\scopes-actives.txt" | ForEach-Object { Set-DhcpServerv4Scope -ScopeId $_ -State Active }
  8. Retire the Windows role

    Only after an observation period: unauthorize the server in Active Directory and stop the service. This stays reversible until the role is uninstalled.

    This script changes the Windows server and Active Directory.

    PowerShell
    Remove-DhcpServerInDC -DnsName $env:COMPUTERNAME
    Stop-Service DHCPServer; Set-Service DHCPServer -StartupType Disabled

DNS migrates the same way from the same page: export primary zones as zone files, import them one by one, and lower the TTL to 300 s the day before switchover.