get-DNSCientServer configuration

Hello, If I run these iteratively, I see the output I want:


Get-DnsClientServerAddress -InterfaceIndex <selected previsouly> | select DetailedStatus

Get-DnsClientGlobalSetting | select SuffixSearchList -ExpandProperty SuffixSearchList

How do I get:

~ Iterate through all the server’s adapters and only give me output where there is an IP v 4 address
~ take this output and show me the DNS client IPs listed (typically would be 3 here)
~ for that adapter determined in #1 above, output all the DNS suffix settings


Are you running this locally or do you have a list of remote servers? (having issues to submit replies)

Ok, I have been playing around with this a little bit. I hope I was able to understand your requirements. I am assuming you have a list of target servers in a file in C:\ with the name ServerList.txt.

The regex expression to identify IPv4 IP addresses is not perfect but should be enough for this purpose. Coming up with a 100% accurate regex expression would be much harder and way more complex.

$Servers = Get-Content C:\ServerList.txt

foreach ($Server in $Servers) {

    $Session = New-CimSession -ComputerName $Server -Name "$Server_Session"
    $NICIndex = Get-NetAdapter -CimSession $Session | Where-Object Status -EQ 'Up'

    foreach ($Index in $NICIndex) {
        $DNSAddress = Get-DnsClientServerAddress -InterfaceIndex $Index.InterfaceIndex -CimSession $Session | Where-Object ServerAddresses -Match '\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'
        $DNSAddress = ($DNSAddress | Select-Object -ExpandProperty ServerAddresses) -join ','
        $DNSObject = [PsCustomObject]@{
            'Server' = $Server
            'Index' = $Index.InterfaceIndex
            'InterfaceName' = $index.Name
        Add-Member -InputObject $DNSObject -MemberType NoteProperty -Name DNSAddress -Value $DNSAddress

        $Suffix = (Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList) -join ','

        Add-Member -InputObject $DNSObject -MemberType NoteProperty -Name Suffix -Value $Suffix

        Write-Output $DNSObject


    Remove-CimSession -ComputerName $Server


This works great Fer, thanks. Let me try and export the results to csv and see if anything’s missing

Fer, I’m over my head with that not sure where to put the export-csv. Does your work need to go in a variable first something like:

$Results = <Fer code>

$Results | Export-Csv etc


Line 26: “Write-Output $DNSObject”. Replace it with:

Export-Csv -InputObject $DNSObject -Append -NoTypeInformation -Path <your_path_to_csv_here>

Or if you keep both “Write-Output” and “Export-Csv” the output will go to the csv file and will be displayed on the screen as well.

Write-Output $DNSObject

Export-Csv -InputObject $DNSObject -Append -NoTypeInformation -Path <your_path_to_csv_here>

(Keep getting errors when trying to submit replies)