SHARE
TWEET

Set-ServersDNS

jmeg8r Feb 12th, 2019 638 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ?#Author: James Cruce https://astgl.com
  2. #Date: 07/25/18
  3. #Version: 1.0
  4. # Script assumes you are logged into an account with local Administrator rights for the remote servers
  5. # This will work for all Windows computers including both physical and virtual servers
  6.  
  7.  
  8. #Variables
  9. $servers = $null
  10. $NIC = $null
  11. $i = $null
  12.  
  13. #This loads the contents of the text file into an array
  14. $servers = Get-Content "c:\Test\servers.txt"
  15.  
  16. #This prompts for your admin credentials
  17. #$cred = Get-Credential
  18.  
  19.  
  20. #This section is a loop to apply the correct DNS settings
  21. foreach ($i in $servers)
  22.     {$i + "`n" + "======================"; ($NIC = Get-WMIObject Win32_NetworkAdapterConfiguration -ComputerName $i | Where-Object{($_.IPEnabled) -eq 'TRUE'})
  23.            
  24.             $NewDNS = '192.168.10.250','192.168.0.250'
  25.             $NIC.SetDNSServerSearchOrder($NewDNS)
  26.             $NIC.SetDynamicDNSRegistration('TRUE')
  27.             $NIC.SetDNSDomain('yourdomain.com'), $null
  28.             $NIC.SetWINSServer('','')
  29.          
  30.            
  31.         #Sets 'Append these DNS suffixes (in order)' setting
  32.         $DNSSuffix = 'yourdomain.com','yourdomain.local'
  33.         Invoke-WMIMethod -path Win32_NetworkAdapterConfiguration -Name SetDNSSuffixSearchOrder -ArgumentList @($DNSSuffix), $null
  34.    
  35.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top