Change DNS setttings

This topic contains 1 reply, has 2 voices, and was last updated by  Richard Diphoorn 2 months, 4 weeks ago.

  • Author
    Posts
  • #71300

    Stuart
    Participant

    Hi,

    I have the following to change DNS settings on remote computers.
    I would like to be able to report back on all clients in the clients.txt file that failed to get their settings updated
    Thanks

    $dnsservers = "192.168.60.4","192.168.60.51"
    $computers = Get-Content "C:\clients\clients.txt"
    foreach ($comp in $computers) {
    $adapters = Get-WmiObject -q "select * from win32_networkadapterconfiguration where ipenabled='true'" -ComputerName $comp
    foreach ($adapter in $adapters)
    {
    $adapter.setDNSServerSearchOrder($dnsservers)
    }
    }

  • #71323

    Richard Diphoorn
    Participant

    Why you don't use Set-DnsClientServerAddress? With this you can use the parameter -ErrorAction Stop, and you could put the whole thing in a try/catch construct.

You must be logged in to reply to this topic.