Thursday, January 26, 2012

Use Powershell to change DNS entries on multiple machines

cls # Clear Screen
Remove-Variable -Name * -Force -ErrorAction SilentlyContinue # remove any lingering variables
$content = get-content c:\scripts\powershell\DNS\fixdnsstpete.txt
foreach ($comp in $content)
{
if (Test-Connection -ComputerName $comp -count 1 -Quiet)
  {
  $comp
  $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -comp $comp | where{$_.IPEnabled -eq “TRUE”}
  Foreach($NIC in $NICs)      {
      $DNSServers = ('170.12.8.249','170.12.10.173','170.12.144.17','170.12.144.227')
      $NIC.SetDNSServerSearchOrder($DNSServers)
      }
  }
}

No comments:

Post a Comment