我正在尝试更改NIC卡上的DNS服务器。有些机器有超过1个NIC(LAN)卡。到目前为止,我创建了以下脚本。
$servers = Get-Content .\Server.txt
$DNSServers = "8.8.8.8","2.2.2.2"
foreach ($server in $servers) {
if(Test-Connection -ComputerName $server -Count 1 -ea 0) {
$prisecdns = Get-WMIObject -Query "select * from Win32_NetworkAdapterConfiguration where IPEnabled = true and DHCPEnabled = False and ipconnectionmetric = 1" -ComputerName $server
$prisecdns.SetDNSServerSearchOrder($DNSServers)
$prisecdns.SetDynamicDNSRegistration("TRUE")
ipconfig /flushDns | Out-Null
Write-Host "DNS Cache Flushed" -ForegroundColor Green
# Register the DNS
ipconfig /registerdns | Out-Null
Write-Host "DNS Regsitered" -ForegroundColor Green
}
}
我不确定上面的脚本在多个网络适配器的情况下是否能正常工作。
有人可以就此提出建议吗?
Powershell版本为2。