Change the DNS from a list of Servers

Posted by robd on October 27, 2016

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:"

   #Change the settings to this
   $DNSServers = "",""

   #After Change - Not tested
   Write-Host "DNS Servers after Change:"

Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

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