If you are running many DHCP scopes for distributed locations with local DNS servers and need to update a large quantity of DNS Server Scope options, you can use the MMC Snapin, but that process uses three windows per scope, but now the DhcpServer PowerShell module is available in the RSAT tools why not script it?
Firstly you will need to add RSAT (Remote Server Administration Tools) to your administration terminal [download available from Microsoft] and then you can use the Set-DhcpServerv4OptionValue CmdLet to update your scope.
Here I have included a Function I use to carry out this action:
#Requires -Module DhcpServer
function Set-grslScopeDNSServers
{
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='Medium')]
Param
(
[Parameter(Mandatory,HelpMessage='Scope ID you wish to change')][string]$scopeid,
[Parameter(Mandatory,HelpMessage='DHCP Server hosting Scope')][string]$dhcpserver,
[Parameter(Mandatory,HelpMessage='New value of DNS Server Option')][string[]]$dnsserver
)
Process
{
Try {
$null = Get-DhcpServerv4Scope -ComputerName $dhcpserver -ScopeId $scopeid -ErrorAction Stop
Remove-DhcpServerv4OptionValue -ComputerName $dhcpserver -OptionId 6 -ScopeId $scopeid
Set-DhcpServerv4OptionValue -ComputerName $dhcpserver -ScopeId $scopeid -DnsServer $dnsserver
Write-Host "DNS servers for DHCP Scope $scopeid have been updated to $dnsserver" -ForegroundColor Green
} Catch {
Write-Host "DHCP Scope $scopeid does not exist on server $dhcpserver" -ForegroundColor Red
}
}
}
- Firstly the Requires statement checks that the DhcpServer Module is installed (part of the RSAT installer)
- The parameters define the $dhcpserver, the ScopeID to change and the new value of the DNSServer DHCP option
- The first line of the Try block checks that the provided ScopeID is present on the DHCP Server if the CmdLet errors ‘ErrorAction Stop’ forces the CmdLet into a terminating error forcing the Catch Block to execute
- If the ScopeID exists on the DHCP server the existing DnsServer Option is removed using Remove-DhcpServerv4OptionValue
- The new DNS server list is added to the scope using Set-DhcpServerv4OptionValue
- If all succeeds then the success message is displayed
- If it fails the error message is displayed