Created
March 16, 2017 22:51
-
-
Save jkavanagh58/e462e8b5875f5040b56d68a79e7fe80e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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