有没有办法在 Powershell 中做到这一点?
REM Stop the DNS Service...
REM (not shown here)
REM DHCP DNS Settings
netsh interface ip set dns "<adapter-name>" dhcp
REM DHCP IP
netsh interface ip set address "<adapter-name>" dhcp
答案1
这是很常见的事情,即 PowerShell 级别 100 的内容。只需使用以下方法搜索即可...
并通过示例获得结果...
基本网络 powershell cmdlet 备忘单,用于替代 netsh、ipconfig、nslookup 等
用 Windows Powershell 替换 Netsh – 基本网络命令
更改网络适配器以使用 DHCP 以下命令可用于重新配置特定网络适配器以使用 DHCP 分配的地址:
$netadapter = Get-NetAdapter -Name Ethernet
$netadapter | Set-NetIPInterface -Dhcp Enabled
$Adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DHCPEnabled -ne 'True' -and $_.DNSServerSearchOrder -ne $null}
$NewDnsServerSearchOrder = "192.168.1.13","192.168.1.14"
$Adapters | ForEach-Object {$_.SetDNSServerSearchOrder($NewDnsServerSearchOrder)} | Out-Null
Set-DNSClientServerAddress –interfaceIndex 12 –ServerAddresses (“10.0.0.1”,”10.0.0.2”)
甚至YouTube使用相同搜索的视频