Setting DNS on remote servers

it2bit2b Member Posts: 117
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?

Comments

  • Hyper-MeHyper-Me Banned Posts: 2,059
    For 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.
  • HeroPsychoHeroPsycho Inactive Imported Users Posts: 1,940
    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 )
    Good luck to all!
  • it2bit2b Member Posts: 117
    HeroPsycho 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
  • it2bit2b Member Posts: 117
    This 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.
Sign In or Register to comment.