Powershell to set new DNS Server for DHCP Reservations
I have IP reservations in my DHCP server for some clients. In this reservations I set an special DNS server for special name resolution. But now I have to change this IP because the DNS service was moved to a new server with new IP address.
I'm ltry to write a script which will change the DNS entry in all my reservation.
Solution:
I create a CSV file with all IP addresses which should be changed to the new DNS server (easy export from DHCP Server).
The column with the IP addreses in the CSV file needs a heading called "IP" and save the CSV in UTF-8 format with Delimiter ";" (even if we don't need it here).
Script to change the settings with log file
If you need to change another DHCP Option you can find all OptionIDs here:
iana.org: DHCP and BOOTP Parameters
I'm ltry to write a script which will change the DNS entry in all my reservation.
Solution:
I create a CSV file with all IP addresses which should be changed to the new DNS server (easy export from DHCP Server).
The column with the IP addreses in the CSV file needs a heading called "IP" and save the CSV in UTF-8 format with Delimiter ";" (even if we don't need it here).
Script to change the settings with log file
# new IP auf DNS server $NewDNS = '192.168.100.100' # import csv file with all IPs $IPs = Import-Csv -Path "C:\data\reservations.csv" -Delimiter ";" -Encoding "UTF8" # write a log file Start-Transcript -Path "C:\data\Set_New_DHCP_Settings.log" # loop through all imported IP addresses foreach ($IP in $IPs){ # change the OptionId 6 (DNS server) for the IPs Write-Host "IP:" $IP.IP "Type:" $IP.Type "- Set new DNS server:" $NewDNS Set-DhcpServerv4OptionValue -ReservedIP $IP.IP -OptionId 6 -Value $NewDNS -Verbose } #Stop log file writing Stop-Transcript
If you need to change another DHCP Option you can find all OptionIDs here:
iana.org: DHCP and BOOTP Parameters