如何在 Windows 7 中自动为 TCP/IPv4 和 TCP/IPv6 重新配置 DNS 服务器?

Ale*_*vis 4 automation domain-name-system scripting tcpip wifi

我需要将DNS 服务器配置的Internet 协议版本 4 (TCP/IPv4)Internet 协议版本 6 (TCP/IPv6)设置从“自动获取 DNS 服务器地址”切换到硬编码值(对于 Google 的 DNS 服务器)并返回。手动执行有点麻烦(我需要转到Control Panel-Network 和 Internet-Network Connections,打开Wireless Network Connection 2,然后打开相应版本的Properties,输入 DNS 服务器值,然后重复另一个)。是否有可以自动化该过程的实用程序或脚本?谢谢。

Luc*_*man 8

在 PowerShell 中:

$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'" 
$DNSServers = "8.8.8.8","8.8.4.4"  
$wmi.SetDNSServerSearchOrder($DNSServers)
Run Code Online (Sandbox Code Playgroud)

还原:

$wmi.SetDNSServerSearchOrder()
Run Code Online (Sandbox Code Playgroud)

(无参数=null,这将使其回到自动模式)

参考:

http://fatbeards.blogspot.com/2008/06/change-dnswins-ip-on-multiple-servers.html

http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/28/use-powershell-to-configure-static-ip-and-dns-settings.aspx