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

The Process of Adding a New Hyper-V Server Into a Cluster and the Associated Virtual Machine Manager (VMM)

These are the steps: Install WindowsWindows 2019 Data Center Edition is the standard as of…

How To Use Command Line to Configure iDrac Settings

Step 1: Install RacADM $computerlist=@' SERVER1 SERVER2 '@ $computernames=@($computerlist -split "`n")|%{$_.Trim()} $fileURL="https://dl.dell.com/FOLDER08543783M/1/DellEMC-iDRACTools-Web-WINX64-10.3.0.0-4945.exe" $expectedExecutable='racadm.exe' $expectedInstallPath='C:\Program Files\Dell\SysMgt\iDRACTools\racadm'…

A Simple Home Network Setup Using SonicWall & Ubiquiti Equipment

Overview: Internet Service Providers would terminate their wiring at the customer premise equipments (CPE) as…