ÿþ$ErrorActionPreference = "SilentlyContinue" $servers = gc "s:\Scripts\servers.txt" #update this path $outfile = "s:\DNS_Update_Logs.txt" #update this path foreach ($server in $servers){ $server = $server.trim() if (Test-Connection -ComputerName $server -Quiet -Count 2){ $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $server -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -ErrorVariable WMIError |where{$_.DHCPEnabled -ne "True" -and $_.IPEnabled -eq "True"} if(!$?) { $result = $server+" - WMI Error or dont have access, check following error $WMIerror" $result | Out-File $outfile -Append -Confirm:$false Write-Host $server" - Could not connect to server check log file for more details" -ForegroundColor Red } else { if ($NICs){ Foreach($NIC in $NICs) { $DNSServers = "198.168.2.100","198.168.2.101" $configureDNS = $NIC.SetDNSServerSearchOrder($DNSServers) if ($configureDNS.ReturnValue -eq "0"){ $result = $server+" - DNS Updated" Write-Host $result -ForegroundColor Green $result | Out-File $outfile -Append -Confirm:$false } else { $result = $server+" - DNS Update Failed" Write-Host $result -ForegroundColor DarkRed $result | Out-File $outfile -Append -Confirm:$false } } } else { $result = $server+" - DHCPEnabled or no IP Address enabled" Write-Host $result -ForegroundColor DarkRed $result | Out-File $outfile -Append -Confirm:$false } } } else { $result = $server+" - Not Reachable" Write-Host $result -ForegroundColor DarkRed $result | Out-File $outfile -Append -Confirm:$false } } $ErrorActionPreference = "Continue"