如果 NIC DNS 为真,则写入 Regkey

Write Regkey if NIC DNS is true

如果某个参数为真,我正在尝试通过 powershell 编写注册码。也就是说,DNS 主地址是 192.192.192.192(对于已经具有 DNS 条目的 NIC)。

这是我的:

$adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object 
{$_.DNSServerSearchOrder -cmatch "192.192.192.192"} 

If ($_.DNSServerSearchOrder -cmatch "192.192.192.192")  

{

New-Item -Path HKCU:\System\CurrentDNS\DNS -Value "192.192.192.192"

}

我还没有测试过,但这应该可以。

Get-WmiObject Win32_NetworkAdapterConfiguration|%{`
if($_.DNSServerSearchOrder){`
   $_.DNSServerSearchOrder|%{`
      if($_ -match "192.192.192.192"){`
         New-Item -Path HKCU:\System\CurrentDNS\DNS -Value "192.192.192.192"
      }
   }
 }
}