Hi Guys,
I would like to change DNS servers IPs on some remote computers, but i'have first to check that this new DNS servers are rechable by thoses clients, the goal is to check that the new DNS Ips are recheable and port 53 is listening.
Afterthat, if successful, it will update the DNS records by the new ones.
I tried to build a script for doing the job, but i'am still confused by that, if someone can give some help i will appreciate.
Thanks a lot in advance to you powershell gurus :)
Regards
$computers = get-content C:\Temp\input.txt
Foreach ( $computer in $computers) {
IF (Test-Connection -Count 1 -ComputerName $computer -Quiet) {
Write-Host "The remote machine is Online"
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer | where{$_.IPEnabled -eq “TRUE”}
$ipaddress = @{192.168.20.88 192.168.30.89}
$port = 53
$connection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port)
if ($connection.Connected) {
Write-Host "Success"
Foreach($NIC in $NICs) {
Write-Host "DNS Servers before change:"
$NIC.DNSServerSearchOrder
$DNSServers = “198.102.234.125",”198.102.234.126"
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration(“TRUE”)
}
else {
Write-Host "DNS port check is Failed"
}
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE”}
Write-Host "DNS Servers after change:"
$NICs.DNSServerSearchOrder
}
}
Else {
Write-Host "The remote machine is Down"
}