Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, May 27, 2020 5:38 PM
Hello,
Does somebody knows if it's possible to set automatically the DHCP option "006 DNS Server" on dhcp scope please (by powershell script or other)?
Because I will have to remove a DC which have DNS role and I have to set the new DNS server address on many dhcp scope.
Thank you by advance.
Mohamed
All replies (5)
Tuesday, June 2, 2020 10:13 AM âś…Answered
Hi Candy
Thank you for you answer. I solved my issue, the right command line is
import-csv "c:\script\CSVfile" -Delimiter ";" | % {Set-DhcpServerv4OptionValue -cn "dhcpservername" -ScopeId $_.ScopeId -OptionId 6 -value $_.DnsServer.split(',')}
and below the vsc file content:
ScopeID;DNSServer
1.1.1.1;2.2.2.2,33.33.33.3
1.1.1.1;2.2.2.2,33.33.33.3
and it works fine
Thursday, May 28, 2020 3:20 AM
Hi Mohamed,
You can use following powershell cmdlets to set option 006 DNS server. As the picture below:
Set option values for a scope with powershell:
Set-DhcpServerv4OptionValue -ComputerName "dhcpserver.contoso.com" -ScopeId 192.168.1.0 -DnsServer 192.168.1.2
or
Set-DhcpServerv4OptionValue -ComputerName "dhcpserver.contoso.com" -ScopeId 192.168.1.0 -optionid 006 -value 192.168.1.2
For more details about Set-DhcpServerv4OptionValue, please refer to the following link:
Best Regards,
Candy
Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]
Thursday, May 28, 2020 1:50 PM
Hi Candy,
Thank you for your answer, but How can I do to set more than 100 dhcp scope (maybe with importing csv file) , and set a secondary prefered DNS Server.
Thank you
Friday, May 29, 2020 2:19 AM
Hi ,
You can run the following script to update all the DNS in all scopes.(I have tested in my lab and it works fine.)
$scopes = Get-DhcpServerv4Scope
foreach($id in $scopes.ScopeID){
Set-DhcpServerv4OptionValue -ScopeId $id -OptionId 6 -value 1.1.1.1 , 2.2.2.2 , 3.3.3.3
}
For your reference:
Update DHCP multiple scopes option 006
Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
In addition, please understand, I am not a PowerShell expert. Since you question is more related with PowerShell, if the above cmdlet is not helpful, you would better have this asked in powershell forum for better answers.
Here is the link:
You can also find scripts in the Gallery that do what you are asking:
Hope this can help you.
Best Regards,
Candy
Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]
Tuesday, June 2, 2020 1:40 AM
Hi ,
You could mark the useful reply as answer if you want to end this thread up.
If there is anything else we can do for you, please feel free to post in the forum.
Best Regards,
Candy
Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]