DnsClient module: #1 Get-DnsClientServerAddress
Started to investigate the DnsClient module. First cmdlet to catch my eye was Get-DnsClientServerAddress.
Always good to know a way to find the DNS server.
PS> Get-DnsClientServerAddress
InterfaceAlias Interface Address ServerAddresses
Index Family
-------------- --------- ------- ---------------
Bluetooth Network Connection 19 IPv4 {}
Bluetooth Network Connection 19 IPv6 {fec0:0:0:ffff::1, fec0:0:0:ffff::2, fec0:0:0:ffff::3}
WiFi 12 IPv4 {192.168.1.1}
WiFi 12 IPv6 {}
isatap.tiscali.co.uk 14 IPv4 {192.168.1.1}
isatap.tiscali.co.uk 14 IPv6 {}
Ethernet 13 IPv4 {}
Ethernet 13 IPv6 {fec0:0:0:ffff::1, fec0:0:0:ffff::2, fec0:0:0:ffff::3}
Loopback Pseudo-Interface 1 1 IPv4 {}
Loopback Pseudo-Interface 1 1 IPv6 {fec0:0:0:ffff::1, fec0:0:0:ffff::2, fec0:0:0:ffff::3}
Teredo Tunneling Pseudo-I... 15 IPv4 {}
Teredo Tunneling Pseudo-I... 15 IPv6 {}
Now thats OK but I’d like a bit more information – especially the adapter and IP version. We can get that data using Get-NetAdapter from the NetAdapter module.
Get-DnsClientServerAddress |
where {$_.ServerAddresses -and $_.InterfaceAlias -notlike "Loop*" }|
foreach {
$nic = $_
Get-NetAdapter -IncludeHidden -InterfaceIndex $($nic.InterfaceIndex) |
Add-Member -MemberType NoteProperty -Name ServerAddresses -Value $($nic.ServerAddresses) -PassThru |
Add-Member -MemberType NoteProperty -Name AddressFamily -Value $(if ($nic.AddressFamily -eq 2){"IPv4"}else{"IPv6"} ) -PassThru|
select Name, InterfaceDescription, ifIndex, Status, MacAddress, LinkSpeed, AddressFamily, ServerAddresses
}
I restricted the output to those interfaces that had DNS server addresses. Used the interface to get the adapter – notice the use of –IncludeHidden – and then used Add-Member to add the addresses and Address family to the data.
These may be CDXML cmdlets but they work the same as any other cmdlet