Monday, January 24, 2011

Mass change DNS settings or at least identify by DNS

We have quite a few Windows based servers and I'm attempting to figure out either A. How I can change all of their DNS settings automatically (they all have local static IPs) or, failing that, B. at least query what their DNS settings are and sort by those that're using our old DNS servers.

We have both SCCM and SCOM if that helps in the situation.

  • Got powershell? There's a script that does basically what you want (also sets WINS server, but you can easily chop the line out).

    And if you're not comfortable just changing configurations with powershell, this version will simply list the servers and their DNS settings:

    function Set-DNSWINS {
    $NICs = Get-WmiObject Win32_NetworkAdapterConfiguration -Computer $_ -Filter "IPEnabled=TRUE"
    
    foreach($NIC in $NICs) {echo $_ $NIC.DNSServerSearchOrder}
    }
    
    function Get-FileName {
    $computer = Read-Host "Filename of computer names?"
    return $computer
    }
    
    $f = Get-FileName
    Get-Content $f | foreach {Set-DNSWINS}
    

    The easiest way to run this is to copy and paste all the but last line into a powersheel, enter the name of the file (you'll need a file with the servernames whitespace separated) then copy and paste the last line.

    tearman : I take it this works via WMI so it doesn't have any requisites on the servers themselves right?
    Chris S : Yeah, this is all done via WMI. If you have tightened up the firewall it may fail, but otherwise there's no special requirement for the servers.
    tearman : Epic answer by the way, this is great! Thank you.
    From Chris S
  • another answer less work!

    wmic /node:listofnames.txt nicconfig where "ipenabled='true'" call SetDNSServerSearchOrder ("x.x.x.x"),("x.x.x.x")

    From tony roth

0 comments:

Post a Comment