Update DNS server client IP's remotely using WMI


Sometimes you need to update older server says Server 2003 or older and you cannot use Powershell as its not installed, but you can use WMI. here is now....





$servers = get-content ./servers.txt





foreach($server in $servers)





{





       Write-Output "Connect to $server..."





       $nics = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $servers | where { $_.IPEnabled -eq "TRUE"}





       $newDNS = "8.8.8.8","8.8.4.4"





       foreach($nic in $nics)





       {





       Write-output "`tExisting DNS Servers " $nic.DNSServerSearchOrder





       $x = $nic.SetDNSServerSearchOrder($newDNS)





       if($x.ReturnValue -eq 0)





        {





        Write-Output "`tSuccessfully Changed DNS Servers on " $server





              }





       else





              {





              Write-Output "`tFailed to Change DNS Servers on " $server





              }





       }





}


Previous Post Next Post

☕️ Buy me a coffee ?

If any of these articles have helped you out consider buying me a coffee, completely optional, but would be appreciated!

نموذج الاتصال