Get the DNS Addresses from a list of Servers

Posted by robd on October 27, 2016
powershell

As per the title, find the DNS addresses from a text list of servers:

#Get the DNS for a List of Servers

#Get the admin permissions
$LoginPassword = Get-Credential

#Get the list of computers from a text file
$computer = get-content C:\temp\servers.txt

#Get the DNS IP's using the get-wmiobject (using wmi as some servers dont have powershell installed) 
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer -Credential $LoginPassword |where{$_.IPEnabled -eq “TRUE”}

# for each server list the current setting
Foreach($NIC in $NICs) {
   
   Write-Host "DNS Servers:"
   $NIC.DNSHostName
   $NIC.DNSServerSearchOrder
 
}

Tags: ,

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.