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

Windows: Enable Remote Access

# Set remote hostname variable$remoteHost="HV01"# Install psexecInstall-Module -Name psexec# psexec \\$remoteHost reg add "HKLM\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters" /v…

PowerShell: Get SQL Server Backup Statuses

$computername='sql01' function getSqlBackupInfo ($sqlInstanceName=$env:computername, $dbName){ [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") $location=if($sqlInstanceName.Contains("`\")){ "SQLSERVER:\SQL\$sqlInstanceName\Databases" }else{ "SQLSERVER:\SQL\$sqlInstanceName\DEFAULT\Databases" } function getPacificTime($time){ if($time){ [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($time,'Pacific…

Resolving CRM Error Upon Login

Symptom: Error Message when trying to login to CRM [caption id="attachment_7481" align="alignnone" width="237"] INVALID ACTION[/caption]…