Change the DNS from a list of Servers

Posted by robd on October 27, 2016
powershell

Change the DNS from a list of servers:

#Change DNS for a list of servers

#Get the admin permissions
$LoginPassword = Get-Credential

#Get the list of computers from a text file
$computer = get-content C:\temp\servers.txt

#Get the DNS IP's using the get-wmiobject (using wmi as some servers dont have powershell installed) 
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer -Credential $LoginPassword |where{$_.IPEnabled -eq “TRUE”}

# for each server list the current setting
Foreach($NIC in $NICs) {
   
   Write-Host "DNS Servers before  change:"
   $NIC.DNSServerSearchOrder

   #Change the settings to this
   $DNSServers = "10.10.7.1","10.10.7.2"
   $NIC.SetDNSServerSearchOrder($DNSServers)
   #$NIC.SetDynamicDNSRegistration(“TRUE”)

   #After Change - Not tested
   Write-Host "DNS Servers after Change:"
   $NIC.DNSHostName
   $NIC.DNSServerSearchOrder
}

Tags: ,

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.