Setting DNS on remote servers
I need to point a group of W2K3 andW2K8 servers to some new DNS servers (W2K8 domain controllers). I learned the group policy for the DNS Client is only for windows XP.
Does anyone have syntax for netsh or a script for this?
Does anyone have syntax for netsh or a script for this?
Comments
-
Hyper-Me Banned Posts: 2,059For 2008
netsh interface ipv4 set dnsservers "Local Area Connection" static 10.0.0.1 Primary
netsh interface ipv4 add dnsservers "Local Area Connection" 10.0.0.2 index=2
Cant remember the 03 off the top of my head but it differs a lil bit I think. -
HeroPsycho Inactive Imported Users Posts: 1,940Or use PowerShell...
function Set-DNSWINS {
#Get NICS via WMI
$NICs = Get-WmiObject '
-Class Win32_NetworkAdapterConfiguration '
-ComputerName $_ '
-Filter "IPEnabled=TRUE"
foreach($NIC in $NICs) {
$DNSServers = "12.34.5.67","76.54.3.21"
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration("TRUE")
$NIC.SetWINSServer("12.345.67.890", "12.345.67.891")
}
}
function Get-FileName {
$computer = Read-Host "Filename of computer names?"
return $computer
}
$f = Get-FileName
Get-Content $f foreach {Set-DNSWINS}
( FatBeard's Adventures in PowerShell: Change DNS/WINS IP on Multiple Servers )Good luck to all! -
it2b Member Posts: 117HeroPsycho wrote: »Or use PowerShell...
function Set-DNSWINS {
#Get NICS via WMI
$NICs = Get-WmiObject '
-Class Win32_NetworkAdapterConfiguration '
-ComputerName $_ '
-Filter "IPEnabled=TRUE"
foreach($NIC in $NICs) {
$DNSServers = "12.34.5.67","76.54.3.21"
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration("TRUE")
$NIC.SetWINSServer("12.345.67.890", "12.345.67.891")
}
}
function Get-FileName {
$computer = Read-Host "Filename of computer names?"
return $computer
}
$f = Get-FileName
Get-Content $f foreach {Set-DNSWINS}
( FatBeard's Adventures in PowerShell: Change DNS/WINS IP on Multiple Servers )
When I get to the read-host line it prompts me for the text file of servers.If I put the file name it gives me an error:
PS C:\scripts> Get-Content : A positional parameter cannot be found that accepts argument 'foreach'.
Missing property name after reference operator.
At line:1 char:86
+ Get-Content : A positional parameter cannot be found that accepts argument 'foreach'. <<<<
+ CategoryInfo : ParserError: (.:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingPropertyName
Any ideas -
it2b Member Posts: 117This post corrects this same script by adding a pipe in the last line
DNS Script change value - PowerShellCommunity.org - Windows PowerShell Discussion Forums - Using PowerShell - General PowerShell
Get-Content $f | foreach {Set-DNSWINS}
Works great. Thanks.