Link to home
Start Free TrialLog in
Avatar of iTeam HelpDesk
iTeam HelpDesk

asked on

Force DNS Settings on Domain Network

So I know there is a way but can't seem to find it.  Server 2012 Domain Network.  How do I force all workstations to use the IP and DNS settings I want on the network workstations.  A lot of workstations have the DNS manually configured and I want to force it thru the domain instead of going to each workstation manually.  The group policy in Server 2012 under admin templates/network DNS settings say that is only for Windows XP professional only.  I changed the settings just to try and this did not work.
Avatar of Justin Yeung
Justin Yeung
Flag of United States of America image

Powershell can do the job

search the target machine's network adapter that has ip 192.168.0.x and set Adapter with deserved DNS address
$DNS = "192.168.1.1","192.168.2.1"
$Nic = Get-WmiObject -class win32_networkadapterconfiguration -computername FQDNofcomputer | ? {$_.Ipaddress -like "192.168.0.*"}
$Nic.SetDNSServerSearchOrder($DNS)

Open in new window


if you want to change the dns server to use dhcp dns remove $DNS from $Nic.setDNSServerSearchOrder($DNS)
$Nic.SetDNSServerSearchOrder()

Open in new window


You can also run this to set a scope of computer, either reading from AD or from a txt file.
I do not know how many machines do you have in your environment

search machine in AD that is windows 7 and adapter that has an IP address
Import-module ActiveDirectory
$Computers = Get-Adcomputer -filter {operatingsystem -like "*windows 7*"} -properties OperatingSystem
foreach ($Computer in $Computers)
{
$DNS = "192.168.1.1","192.168.2.1"
$Nic = Get-WmiObject -class win32_networkadapterconfiguration -computername $Computer.dnshostname| ? {$_.Ipaddress -ne $null}
$Nic.SetDNSServerSearchOrder($DNS)
}

Open in new window


or do it from txt file

import C:\computers.txt file and find adapter that has an IP address (not equal nothing)
$Computers = get-content c:\computers.txt
foreach ($Computer in $Computers)
{
$DNS = "192.168.1.1","192.168.2.1"
$Nic = Get-WmiObject -class win32_networkadapterconfiguration -computername $Computer | ? {$_.Ipaddress -ne $null}
$Nic.SetDNSServerSearchOrder($DNS)
}

Open in new window


hope this help.
ASKER CERTIFIED SOLUTION
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iTeam HelpDesk
iTeam HelpDesk

ASKER

This was what I ended up doing last night.  Thank you.