As Administrators, you may work with 10 Exchange Servers in an environment or you may work with 500. Consistency within configuration is essential as something small like the incorrect DNS server can cause havoc and send you down a rabbit hole trying to find the root cause.

I put together a script that goes and pulls the DNS Servers for each adapter on an Exchange Server listed by Server Name that you can compare. DNS is key with Exchange Servers being able to query Active Directory and all other services.

Line 2 will need to be updated manually where you specify your Exchange Servers as follows:

$servers = "Server1", "Server2", "Server3"

In the figure below, we can see the output in a table that shows the DNS server information

Get DNS info PowerShell Script

The same is shown when run in PowerShell ISE (includes the script):

running the DNS info script in PowerShell ISE

Script

The script can be used as is, you may want to change the $Servers value to read a csv file instead of using individual servers, however here is the script:

# List of server names or IP addresses
$servers = "Server1", "Server2", "Server3"

# Array to store custom objects with DNS information
$results = @()

foreach ($server in $servers) {
    try {
        # Query DNS settings using WMI
        $dnsSettings = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $server | Where-Object { $_.IPAddress -ne $null }

        foreach ($dns in $dnsSettings) {
            # Create custom object for each DNS entry
            $dnsInfo = [PSCustomObject]@{
                Server = $server
                Description = $dns.Description
                DNSServer = $dns.DNSServerSearchOrder -join ', '
                                
            }

            # Add the object to the results array
            $results += $dnsInfo
        }
    } catch {
        Write-Host "Error checking DNS settings on server: $_"
    }
}

# Display results in a table
$results | Format-Table -AutoSize

If the screen output has too much data, consider exporting the file to a format of choice by modifying the last line.

Hope it helps.

    wpChatIcon

    Discover more from Everything-PowerShell

    Subscribe now to keep reading and get access to the full archive.

    Continue reading