PowerShell: DHCP Server Scope Options Editing

Occasionally, internal DNS server changes as machines are refreshed and/or decommissioned. DHCP servers should also update according to these changes. Here is a PowerShell snippet that will ensure that this task is as painless as possible

# Set global variables
[System.Collections.ArrayList]$dnsArray = $dnsClientServerIP1,$dnsClientServerIP2 #or convert to Array via method {$dnsArray}.Invoke()

# Use this function only if all scopes are using the same DNS Client Server IP addresses
function setStandardizedDns{
foreach ($scope in $scopes){
Set-DhcpServerv4OptionValue -ComputerName $dhcpServer1 -Force -ScopeId $scope -DnsServer $dnsArray -WinsServer $dnsArray # Optional for edits: -DnsDomain $dnsDomain -Router $router

# Use this function for one-off scopes that have different primary Client DNS Server IP than the standardized $dnsArray
function setUniqueDNS($scopeID,$scopeClientPrimaryDNS){
Set-DhcpServerv4OptionValue -ComputerName $dhcpServer1 -ScopeId $thisScope -DnsServer $thisDnsArray -WinsServer $thisDnsArray -Force

function setServerDns{
Set-DhcpServerv4OptionValue -ComputerName $dhcpServer1 -DnsServer $dnsArray -WinsServer $dnsArray -DnsDomain $dnsDomain


Leave a Reply

Your email address will not be published. Required fields are marked *