Skip to content

Instantly share code, notes, and snippets.

@jkavanagh58
Created March 16, 2017 22:51
Show Gist options
  • Save jkavanagh58/e462e8b5875f5040b56d68a79e7fe80e to your computer and use it in GitHub Desktop.
Save jkavanagh58/e462e8b5875f5040b56d68a79e7fe80e to your computer and use it in GitHub Desktop.
$file = 'C:\etc\srv03sb.csv'
$computers = Import-Csv -Path $file -Header ComputerName, IPAdress, DNSServer1, DNSServer2, DNSServer3
foreach ($computer in $computers) {
if(Test-Connection -ComputerName $computer.ComputerName -Count 1 -ea 0) {
try {
$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $computer.ComputerName -EA Stop | ? {$_.IPEnabled}
}
catch {
Write-Warning "Error occurred while querying $computer."
Continue
}
foreach ($Network in $Networks) {
$dns = @($computer.DNSServer1,$computer.DNSServer2)
$Network.SetDNSServerSearchOrder($dns) | Out-Null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment