Posted On July 10, 2019

PowerShell: DHCP Server Scope Options Editing

kimconnect 0 comments
blog.KimConnect.com >> Codes , Networking >> 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
$dhcpServer1="DC01.kimconnect.com"
$dnsDomain="intranet.kimconnect.com"
$router="192.168.1.1"
$dnsClientServerIP1="10.10.10.10"
$dnsClientServerIP2="10.10.10.11"
[System.Collections.ArrayList]$dnsArray = $dnsClientServerIP1,$dnsClientServerIP2 #or convert to Array via method {$dnsArray}.Invoke()
$scopes=(Get-DhcpServerv4Scope).ScopeID.IPAddressToString

# 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){
$thisScope=$scopeID
$thisDnsArray=,$scopeClientPrimaryDNS+$dnsArray
Set-DhcpServerv4OptionValue -ComputerName $dhcpServer1 -ScopeId $thisScope -DnsServer $thisDnsArray -WinsServer $thisDnsArray -Force
}

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

setStandardizedDns;
setServerDns;

Leave a Reply

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

Related Post

PowerShell: Install PSTools

if(!(get-command psexec -ea SilentlyContinue)){ if (!(Get-Command choco.exe -ErrorAction SilentlyContinue)) { Set-ExecutionPolicy Bypass -Scope Process -Force;…

Dev Environment Technitium DNS Server

Windows: $technitiumPortableDownload="https://download.technitium.com/dns/DnsServerPortable.zip"$tempDir="C:\Temp"; $extractionDir="C:\Technitium" $destinationFile = "$tempDir\DnsServerPortable.zip"; try{[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12}catch{} New-Item -ItemType Directory -Force -Path $tempDir…

RJ45 Ethernet & RJ11 Telephone Cables

There are three options to Ethernet cable wiring: T568-A, T568-B, and cross-over. AT&T & other…