-
Notifications
You must be signed in to change notification settings - Fork 0
/
setdns.ps
45 lines (29 loc) · 1.09 KB
/
setdns.ps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Set the primary DNS server to the desired value
$primaryDnsServer = "8.8.8.8"
$interfaceIndex = (Get-NetAdapter).ifIndex
# Get the current DNS server addresses
$currentDnsServers = (Get-DnsClientServerAddress -InterfaceIndex $interfaceIndex).ServerAddresses
# Store the current secondary DNS server in a variable
$secondaryDnsServer = $currentDnsServers[1]
# Set the primary and secondary DNS servers
Set-DnsClientServerAddress -InterfaceIndex $interfaceIndex -ServerAddresses $primaryDnsServer,$secondaryDnsServer
OR
----------
Get-DnsClient | Set-DnsClientServerAddress -ServerAddresses ("1.1.1.1","1.0.0.1")
----------
OR
----------
Set-DnsClientServerAddress -InterfaceAlias 'Ethernet' -ServerAddresses '192.168.0.4','192.168.0.5'
-------------
OR
--------
$EthAdapters = Get-NetAdapter -Name Ether*
foreach ($EthAdapter in $EthAdapters)
{
Set-DnsClientServerAddress -ServerAddresses 192.168.0.1, 192.168.0.2 -PassThru -InterfaceAlias $EthAdapter.name -Verbose
}
-------
OR
--------
Get-NetAdapter -name ethernet*|Set-DnsClientServerAddress -ServerAddresses ("8.8.8.8","8.8.8.9")
-------