How to get the DNS of domain joined server from a list or specific OU ?

Hi Folks,

I'm about to decommission one of the old server which is currently serving as DNS server in my Data Center.
Most or lots of the legacy servers in my AD domain got the static DNS pointing to this server. So how can I get the list of the server with its DNS settings in a CSV format ?

Example:
Server name, DNS1, DNS2

Thanks.
LVL 9
Senior IT System EngineerIT ProfessionalAsked:
Who is Participating?
 
footechCommented:
Line 1 defines an array of IP addresses you want to use as DNS servers.  Multiple would be like
$DnsServers = [ipaddress[]]("10.10.0.1","10.10.0.2")
Line 8 calls the SetDnsServerSearchOrder WMI method, piping to Out-Null to discard the output.  Yes, it changes the  statically assigned DNS server to 10.10.0.1.
0
 
footechCommented:
Although it's possible to get this information, if the plan is to replace this server with a new one, why don't you just stand up the new server with the same IP?  Then you don't have to change any config.
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
Use the following script below to get this info...
Import-Module activedirectory
$Computers = Get-ADComputer -Filter *
ForEach ($Computer in $Computers) {
Get-WMIObject -class Win32_NetworkAdapterConfiguration | ? {$_.IPAddress -notlike $Null} | select $Computer.Name, IPAddress, DNSServerSearchOrder | Export-csv "c:\computerDNSIP.csv" -append
}

Open in new window


Will.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Senior IT System EngineerIT ProfessionalAuthor Commented:
Because. New server is already running as new DC & DNS integrated while the old server is still running as the Win 2003 AD DC DNS box
0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
Thanks Will, I'll give it a try in the office on Monday.
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
The command i have created above will get all of the computers in your domain and provide the DnsSearchOrder for your DNS servers. I also had to do something like that before doing some IP cleanup.

Will.
0
 
footechCommented:
Just wanted to make sure you had considered alternatives in case it would save you time.

You can also set the DnsSearchOrder using WMI.  One of the more important points here is to filter out any NICs that you don't want to set (or even try to).
$DnsServers = [ipaddress[]]("10.10.0.1")
Get-ADComputer -Filter * -searchbase "OU=someOU,DC=domain;DC=com" | Select -expandProperty Name | ForEach `
{
    $computer = $_
    Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'true' AND DHCPEnabled = 'false'" -ComputerName $computer |
         Where {$_.DnsServerSearchOrder -ne $null} | ForEach `
        {
            $_.SetDnsServerSearchOrder($DnsServers) | Out-Null
        }
}

Open in new window

0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
Thanks Will.

@Footech: May I know what's your script does in Line 1 and Line 8 ? Does it change the statically assigned DNS server into 10.10.0.1 ?
0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
@Will:

Somehow the script failed to get the list of current server from specific OU and its DNS server into the Excel spreadsheet:

$Computers = Get-ADComputer -Filter * -SearchBase "OU=Production Servers,OU=Servers,DC=Domain,DC=com"
ForEach ($Computer in $Computers) {
	Get-WMIObject -class Win32_NetworkAdapterConfiguration | ? {$_.IPAddress -notlike $Null} | select $Computer.Name , IPAddress, DNSServerSearchOrder | Export-csv "C:\TEMP\DNSIP.csv" -Append
} 

Open in new window


Error code below:
Export-csv : Cannot append CSV content to the following file: C:\TEMP\DNSIP.csv. The appended object does not have a property that corresponds to the following column: 
PRODExcMbx01-VM. To continue with mismatched properties, add the -Force parameter, and then retry the command.
At C:\Users\Administrator\AppData\Local\Temp\4c40dff4-c8ba-4ab3-ad94-1e68d0c43a96.ps1:6 char:151
+ ... rSearchOrder | Export-csv "C:\TEMP\DNSIP.csv" -Append
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (PRODExcMbx01-VM:String) [Export-Csv], InvalidOperationException
    + FullyQualifiedErrorId : CannotAppendCsvWithMismatchedPropertyNames,Microsoft.PowerShell.Commands.ExportCsvCommand

Open in new window


and the result of the CSV is shown below:
#TYPE Selected.System.Management.ManagementObject
"PRODExcMbx01-VM","IPAddress","DNSServerSearchOrder"
,"System.String[]","System.String[]"

Open in new window

0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
thanks !
0
 
footechCommented:
Will's needed the -ComputerName parameter for the Get-WmiObject command.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.