UPDATE DNS IP in List of computers

#Input file is CSV file with headers IPaddress

$Computers = import-csv “c:\temp\servers.csv”

ForEach ($Computer in $Computers) {
Write-Host “$($Computer.IPAddress): ” -ForegroundColor Yellow
Invoke-Command -ComputerName $Computer.IPAddress -ScriptBlock {

#input Cirrect DNS IP’S in the feals
$NewDnsServerSearchOrder = “10.10.1.200”,”10.10.1.106″
$Adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DHCPEnabled -ne ‘True’ -and $_.DNSServerSearchOrder -ne $null}

    # Show DNS servers before update
    Write-Host "Before: " -ForegroundColor Green
    $Adapters | ForEach-Object {$_.DNSServerSearchOrder}

    # Update DNS servers
    $Adapters | ForEach-Object {$_.SetDNSServerSearchOrder($NewDnsServerSearchOrder)} | Out-Null

    # Show DNS servers after update
    $Adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DHCPEnabled -ne 'True' -and $_.DNSServerSearchOrder -ne $null}
    Write-Host "After: " -ForegroundColor Green
    $Adapters | ForEach-Object {$_.DNSServerSearchOrder}
}

}

4 Comments

  1. Thanx for the effort, keep up the good work Great work, I am going to start a small Blog Engine course work using your site I hope you enjoy blogging with the popular BlogEngine.net.Thethoughts you express are really awesome. Hope you will right some more posts.

Leave a Reply

Your email address will not be published.