?
Solved

Powershell script to configure DNS setting

Posted on 2016-07-15
3
Medium Priority
?
61 Views
Last Modified: 2016-07-28
Need some help

I need to come up with a Powershell script to change multiple Domain Controllers DNS settings.  

Please note: Ip address does not need to change, only dns address & dns search order

Sites 1&,2 should have dns address: 172.16.10.12, 172.16.10.13 (search order test.lab, testb.lab)   &  Site 3 should have 172.16.10.13, 172.16.10.14, 172.16.10.12 (Search order Testb.lab, Test.lab)

DNS Settings:  172.16.10.12, 172.16.10.13, 172.16.10.14      
DNS Search order:  Test.lab, TestB.lab

I will like to use either csv(import-csv) or txt(get-content) file will lists all of my DC's.    CSV file will likely have columns which lists DNS address, DNS search order, Site Location.

Example
Test.lab
Domain controllers, DC1,DC2,DC3,DC4,DC5,DC6 ,DC7,DC8,DC9

Site 1 - DC1,DC2,DC3
Site 2 - DC4,DC5,DC6
Site 3 - DC7,DC8,DC9

Please note: The reason I list the sites so that I can organize which DC's will receive DNS settings and DNS search order base on its site location.
0
Comment
Question by:JCJohnson76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 41712939
Your text or CSV file does not allow to assign the DNS suffix search order. Best structure would be
site,dc
1, DC1
1, DC2
1, DC3
2, DC4
2, DC5
...

Open in new window

and another one for DNS and suffixes
site, DNS, order
1, "172.16.10.12, 172.16.10.13, 172.16.10.14", "Test.lab, TestB.lab"
...

Open in new window

Which OS are those DCs running? W8/2012 allows to use some cmdlets, prior OS requires to use e.g. netsh.
0
 

Author Comment

by:JCJohnson76
ID: 41712965
Running 2008 R2 DC's,

Can you provide detail syntax on the setup of this solution,  

Thanks for the reply, & getting back to so soon
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 41713150
That's getting pretty involved. Looks like we have to mix up some different tools.
Are you able to run PS commands remotely (using WSMAN) on those DCs?
As an intermediate step, here what I would run locally using variables as they came from the CSVs I suggested:
$DNSServers = '172.16.10.12, 172.16.10.13, 172.16.10.14'
$DNSSuffixes = 'test.lab, testb.lab'
Set-ItemProperty HKLM:System\CurrentControlSet\Services\TCPIP\Parameters SearchList $DNSSuffixes
set idx=1
$DNSServers.Split(',') | 
  % {
    if ($idx -eq 1) {
      "set dnsservers ""LAN""  $_ "
    } else {
      "add dnsservers ""LAN"" $_ index=$idx no"
    }
    $idx++
  } | netsh interface IP

Open in new window

0

Featured Post

Bringing Advanced Authentication to the SMB Market

WatchGuard announces the acquisition of advanced authentication provider, Datablink, with one mission – to bring secure authentication to SMB, mid-market, and distributed enterprises with a cloud-based solution, ideal for resale via their established channel & MSSP community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question