Update DNS Server Settings for DHCP Reservations with PowerShell

When a DNS service is moved to a new server, updating all related DHCP reservations manually can quickly become tedious. PowerShell is a much better option because the DHCP cmdlet Set-DhcpServerv4OptionValue can change option 6, which is the DNS server setting, for reserved IPv4 addresses directly.

In this case, the goal was to update the DNS server entry for selected DHCP reservations after the DNS service had been migrated to a new IP address. Instead of editing every reservation in the DHCP console, a CSV-based PowerShell approach made it possible to process all required entries in a consistent and repeatable way.

Scenario

Some DHCP reservations were configured with a dedicated DNS server for special name resolution. After the DNS service was moved to a new system, the old IP address had to be replaced in every affected reservation so the clients would continue using the correct DNS endpoint.

This kind of task is easy to underestimate. A manual change works for a handful of entries, but once multiple reservations are involved, the risk of mistakes increases and the process becomes unnecessarily time-consuming.

CSV-based approach

The practical solution was to export or build a CSV file that contains all IP addresses whose reservation-specific DNS server setting should be changed. PowerShell’s Import-Csv cmdlet reads CSV data into objects, and it supports custom delimiters, which makes it well suited for semicolon-separated administrative data files.learn.microsoft+1

The important part is that the CSV contains a column named IP, because that value is used as the reserved IP address in the update process. An additional column such as Type can still be useful for documentation, filtering, or logging, even if the actual update only depends on the IP address.

Example CSV structure:

IP;Type
192.168.1.100;Server
192.168.1.101;Workstation

The file should be saved in UTF-8 format and use ; as the delimiter so the import works reliably with the expected structure. Import-Csv maps each column to an object property, which makes it easy to loop through the entries afterward.

How the script works

The script reads the CSV file, loops through all imported IP addresses, and updates DHCP option 6 for each reservation. Microsoft documents that Set-DhcpServerv4OptionValue can set DNS server values for a specific reservation, which is exactly what makes this automation approach so effective for migration tasks like this.

The script also records its activity with Start-Transcript, which creates a text log of the PowerShell session. That logging is useful for documentation and troubleshooting, especially when changes are made in production or across many reservations.

Why this method is useful

This method separates the list of affected reservations from the script logic. The PowerShell code stays reusable, while the CSV file can easily be adjusted whenever a different group of reservations needs to be changed.

It also reduces the chance of configuration drift. Instead of editing reservations one by one in the GUI, the same setting is applied systematically to every listed entry, which makes the result easier to verify and easier to repeat later.

Download

The full PowerShell script is available here:

Download the script from GitHub

Notes

Before running the script, the DHCP Server PowerShell module must be available and the account needs the required permissions to manage DHCP reservations. It is also worth validating the CSV content first, because the script depends on correct IP values and a properly named IP column.learn.microsoft+1

A short lab test is recommended before using the script in production. Even though the change itself is simple, DHCP option changes directly affect client network behavior and should therefore be verified carefully.

Schreibe einen Kommentar