PowerShell Genie

Export DNS client configuration

Script 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

List configured IPv4 DNS servers with Get-DnsClientServerAddress. Pair each interface with its resolver addresses and exclude empty lists.

The script

1PS> Get-DnsClientServerAddress -AddressFamily IPv4 | Where-Object ServerAddresses | Select-Object InterfaceAlias,ServerAddresses

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 InterfaceAlias AddressFamily ServerAddresses
    2 -------------- ------------- ------------------------
    3 Ethernet IPv4 10.20.30.10, 10.20.30.11
    4 Wi-Fi IPv4
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-DnsClientServerAddress -AddressFamily IPv4 | Where-Object ServerAddresses | Select-Object InterfaceAlias,ServerAddresses
    1. Stage 1Get-DnsClientServerAddress-AddressFamily
    2. Stage 2Where-ObjectPositional values or no named parameters
    3. Stage 3Select-ObjectPositional values or no named parameters

      How it works

      Get-DnsClientServerAddress limited to IPv4 returns the configured resolvers per interface, Where-Object drops interfaces with an empty list, and the projection pairs the interface alias with its ServerAddresses collection.

      Adapting it

      Add a calculated property that joins ServerAddresses with a comma so the values survive an export, and pass -CimSession to run the same query across a list of hosts.

      If the result is unexpected

      DNS client configuration is associated with the wrong adapter.

      Machines may have virtual interfaces, multiple address families and changing interface names.

      1. Compare InterfaceIndex, address family and adapter status for the affected connection.

      Validate the result

      The exported DNS settings belong to the intended interface and address family.

      Keep the check reliable

      Retain interface identifiers alongside friendly names in configuration reports.

      Primary documentation

      PowerShell objects and pipelines documentation

      Continue
      Genie guideExport DNS client configuration

      List configured IPv4 DNS servers with Get-DnsClientServerAddress. Pair each interface with its resolver addresses and exclude empty lists.