获取远端计算机的DNS

  1. 批量查询服务器DNS设置:
    先将要查询的服务器列表保存在一个文本文件servers.txt中,然后保存以下脚本到getdns.ps1文件中,最后在PowerShell中执行getdns.ps1脚本,结果会输出到serverdns.txt中。此脚本中搜索的是网卡名称为LAN的网卡然后进行设置,如果网卡为别的名称,请作相应的更改,所以合理规划并定义网卡名称也是很有必要的。
    脚本一,获取DNS,IP,Gateway
    KaTeX parse error: Expected 'EOF', got '\ServerList' at position 27: … get-content c:\̲S̲e̲r̲v̲e̲r̲L̲i̲s̲t̲.txt Foreach(computer in $computers){
    Get-WMIObject Win32_NetworkAdapterConfiguration -Computername KaTeX parse error: Expected '}', got 'EOF' at end of input: … Where-Object {.IPEnabled -match “True”} | Select-Object -property DNSHostName,ServiceName,@{N="DNSServerSearchOrder"; E={"$($_.DNSServerSearchOrder)"}}, @{N='IPAddress';E={$_.IPAddress}}, @{N='DefaultIPGateway';E={$_.DefaultIPGateway}} | FT | Out-File -Encoding unicode -Append -FilePath c:\serverdns.txt } 脚本二,只获取DNS $computers = get-content F:\tools\ServerList.txt Foreach($computer in $computers){ Get-WMIObject Win32_NetworkAdapterConfiguration -Computername $Computer |
    Where-Object {KaTeX parse error: Expected 'EOF', got '}' at position 26: …d -match "True"}̲ | ` Select-Obj…($
    .DNSServerSearchOrder)"}} | FT | Out-File -Encoding unicode -Append -FilePath f:\tools\serverdns.txt }

脚本三,获取IP,DNS成CSV文件
$computers = get-content F:\tools\ServerList.txt
KaTeX parse error: Expected 'EOF', got '\tools' at position 14: CSVFile = "F:\̲t̲o̲o̲l̲s̲\dnsaddress.csv…computer in $computers){
Get-WMIObject Win32_NetworkAdapterConfiguration -Computername KaTeX parse error: Expected '}', got 'EOF' at end of input: … Where-Object {.IPEnabled -match “True”} | `
Select-Object -property DNSHostName,ServiceName,@{N=“DNSServerSearchOrder”;
E={" ( ( (
.DNSServerSearchOrder)"}},
@{N=‘IPAddress’;E={$_.IPAddress}}|Export-Csv -Path $CSVFile -NoTypeInformation -Encoding UTF8 -Append
}

  1. 批量修改服务器DNS设置:
    先将要修改的服务器列表保存在一个文本文件servers.txt中,然后保存以下脚本到setdns.ps1文件中,最后在PowerShell中执行setdns.ps1脚本即可。
    KaTeX parse error: Expected 'EOF', got '\servers' at position 26: …= get-content .\̲s̲e̲r̲v̲e̲r̲s̲.txt Foreach(computer in $computers)
    {
    $lannic = get-wmiobject win32_networkadapter -computername KaTeX parse error: Expected '}', got 'EOF' at end of input: …omputer |where{.netconnectionid -eq “LAN”}
    $index = $lannic.index
    $lan = Get-WMIObject Win32_NetworkAdapterConfiguration -computername KaTeX parse error: Expected '}', got 'EOF' at end of input: …omputer |where{
    .index -eq $index}
    $DNSServers = “10.1.1.11″,”10.1.1.21″
    l a n . S e t D N S S e r v e r S e a r c h O r d e r ( lan.SetDNSServerSearchOrder( lan.SetDNSServerSearchOrder(DNSServers)
    }

你可能感兴趣的:(Windows\Active,Directory,Powershell)