Get all servers DNS Client settings (2 properties)

I have been determining which cmdlets I want to use to gather all DNS client settings on all servers in my list.

I have this so far:

Get-DnsClientServerAddress 

Get-DnsClientServerAddress -InterfaceIndex <might be different ones> | select DetailedStatus

Get-DnsClientGlobalSetting | select SuffixSearchList -ExpandProperty SuffixSearchList

How can I essentially:

add all of these into one foreach?

My biggest hurdle seems to be how do I query that I only want to return results for an Interface that has an IP v4 address in it? There would only be one…

thank you

When you query the actual properties of the object returned, and not the very friendly formatted default output, you should see the AddressFamily is stored as an integer. Seems it’s 2 for IPv4 and 23 for IPv6. I’m not quite sure what you’re wanting to do with the foreach but this may get you started.

Get-DnsClientServerAddress | Where-Object AddressFamily -eq 2 | Foreach-Object {
    [PSCustomObject]@{
        Server = $env:COMPUTERNAME
        InterfaceAlias = $_.InterfaceAlias
        InterfaceIndex = $_.InterfaceIndex
        AddressFamily  = "IPv4"
        ServerAddresses = $_.ServerAddresses -join ', '
        DetailedStatus = $_.DetailedStatus
        SuffixSearchList = Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList
    }
}

Then to query all your servers I’d recommend just using Invoke-Command

$serverlist = 'dcserver','storageserver','mssql'

Invoke-Command -ComputerName $serverlist -ScriptBlock {
    Get-DnsClientServerAddress | Where-Object AddressFamily -eq 2 | Foreach-Object {
        [PSCustomObject]@{
            Server = $env:COMPUTERNAME
            InterfaceAlias = $_.InterfaceAlias
            InterfaceIndex = $_.InterfaceIndex
            AddressFamily  = "IPv4"
            ServerAddresses = $_.ServerAddresses -join ', '
            DetailedStatus = $_.DetailedStatus
            SuffixSearchList = Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList
        }
    }
} -HideComputerName | Select-Object * -ExcludeProperty runspaceid

Thanks Rob, Invoke-Command for me :vulcan_salute: