Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell script to change DNS

$
0
0
$computer = get-content "C:\dns\dns.txt"
 $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE”} | select PScomputerName,DNSServersearchOrder | where DNS=1.1.1.1
   Foreach($NIC in $NICs) {

$DNSServers = “2.2.2.2",”3.3.3.3"
  $NIC.SetDNSServerSearchOrder($DNSServers)
  $NIC.SetDynamicDNSRegistration(“TRUE”)
 }

I have the need to change the DNS settings on several servers. I am trying to do this using PowerShell and a txt file. Problem being I need to make sure I am only changing the DNS settings on the NICS that currently have a certain IP. I am not able to make this work. Any suggestions on how I could do this? Please see code above

Thanks for your help


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>