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 10
Senior IT System EngineerIT ProfessionalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.