How to get the details of DNS configuration on dc’s

This script will give the details of DNS server configuration on domain controller.

$dcs=Get-Content “DC.txt”
Foreach ($Computer in $dcs)
try {
$Networks = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName $Computer
-ErrorAction Stop
} catch {
“Failed to Query $Computer. Error details: $_”|Out-File dc_DNS.txt -Append
foreach($Network in $Networks) {
$DNSServers = $Network.DNSServerSearchOrder
$NetworkName = $Network.Description
If(!$DNSServers) {
$PrimaryDNSServer = “Notset”
$SecondaryDNSServer = “Notset”
} elseif($DNSServers.count -eq 1) {
$PrimaryDNSServer = $DNSServers[0]
$SecondaryDNSServer = “Notset”
} else {
$PrimaryDNSServer = $DNSServers[0]
$SecondaryDNSServer = $DNSServers[1]
$Computer + “,”+ $PrimaryDNSServer + “,” + $SecondaryDNSServer |Out-File dc_DNS.txt -append
$Computer + “,”+ $er|Out-File dc_DNS.txt -append

Please follow below steps to execute the script.

  • Get the details of domain DCโ€™s and put it in the DC.txt
  • Rename the script to DNS_details.ps1.
  • Execute the script DNS_details.ps1, Output will be stored in dc_DNS.txt.
  • You get the output dc_DNS.txt .

If you have any questions feel free to contact us on also follow us on facebook @windowstechno to get updates about new blog posts.

How useful was this post?

Click on a star to rate it!

Leave a Reply