techthoughts2
12/5/2017 - 2:30 AM

Set DNS

Two examples of setting DNS on an adapter using PowerSehll

$dns1 = "192.168.1.4"
$dns2 = "192.168.1.5"
#-----------------------------------------------------------
#i want to set the DNS for all adapters
try{
    $adapters = Get-NetAdapter -ErrorAction Stop
    foreach($adapter in $adapters){
        Set-DnsClientServerAddress -InterfaceAlias $adapter.InterfaceAlias -ServerAddresses $dns1, $dns2 | Out-Null
    }
}
catch{
    Write-Error $_
}
#-----------------------------------------------------------
#i know the interface i want to set the adapter on
Set-DnsClientServerAddress -InterfaceAlias PublicNetTeam -ServerAddresses $dns1, $dns2 | Out-Null
#-----------------------------------------------------------