 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get DNS IP Settings using PowerShell?
Ipconfig /all command also retrieves the DNS settings for all the network interfaces. This command can be run on both cmd and PowerShell. For example,
Example
PS C:\Users\Administrator> ipconfig /all Windows IP Configuration    Host Name . . . . . . . . . . . . : Test1-Win2k16    Primary Dns Suffix  . . . . . . . : labdomain.local    Node Type . . . . . . . . . . . . : Hybrid    IP Routing Enabled. . . . . . . . : No    WINS Proxy Enabled. . . . . . . . : No    DNS Suffix Search List. . . . . . : labdomain.local Ethernet adapter Ethernet0:    Connection-specific DNS Suffix  . :    Description . . . . . . . . . . . : Intel(R) 82574L Gigabit Network Connection    Physical Address. . . . . . . . . : 00-0C-29-E1-28-E0    DHCP Enabled. . . . . . . . . . . : No    Autoconfiguration Enabled . . . . : Yes    IPv4 Address. . . . . . . . . . . : 192.168.0.108(Preferred)    Subnet Mask . . . . . . . . . . . : 255.255.255.0    Default Gateway . . . . . . . . . : 192.168.0.1    DHCPv6 IAID . . . . . . . . . . . : 33557545    DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-26-A9-34-58-00-0C-29-E1-28-E0    DNS Servers . . . . . . . . . . . : 192.168.0.105    NetBIOS over Tcpip. . . . . . . . : Enabled Tunnel adapter isatap.{5F9A3612-A410-4408-A7A8-368D2E16D6A8}:    Media State . . . . . . . . . . . : Media disconnected    Connection-specific DNS Suffix  . :    Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2    Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0    DHCP Enabled. . . . . . . . . . . : No    Autoconfiguration Enabled . . . . : Yes  But the problem with this command is you can not filter out the results properly. For example, if you need to retrieve the information for a specific interface then you need to write many string manipulation codes in PowerShell.
There are few GET verb commands available for DNS client-side settings. Let's check them.
Get-Command -Verb Get -Noun DNS* Name Version ---- ------- Get-DnsClient 1.0.0.0 Get-DnsClientCache 1.0.0.0 Get-DnsClientGlobalSetting 1.0.0.0 Get-DnsClientNrptGlobal 1.0.0.0 Get-DnsClientNrptPolicy 1.0.0.0 Get-DnsClientNrptRule 1.0.0.0 Get-DnsClientServerAddress 1.0.0.0
To retrieve the data related to DNS client IP settings including domain name like Ipconfig /all command, we need mainly 3 commands.
- Get-DnsClient 
- Get-DnsClientGlobalSetting 
- Get-DnsClientServerAddress 
We will see each command one by one.
Get-DnsClient
This command gets the details of the specific network interfaces configured on the specific computer. This command also helps you to set the DNS server address on the client computers when the Set-DnsClientServerAddress command is pipelined.
When you run this command on the local computer, it gives the details of the local interface.
Get-DnsClient

If you need specific interface address information then use -InterfaceIndex parameter. In the above output Interface Index, 3 is the primary adapter.
Get-DnsClient -InterfaceIndex 3
Output

To get the same settings on the remote server, we can use the -CimSession parameter.
$sess = New-CimSession -ComputerName Test1-Win2k16 Get-DnsClient -Session $sess
Get-DNSClientGlobalSetting
This cmdlet retrieves the DNS client settings which are common to all the interfaces like the DNS suffix search list. Once you run the command, the output will be shown as below.
Output
PS C:\Users\Administrator> Get-DnsClientGlobalSetting UseSuffixSearchList : True SuffixSearchList    : {labdomain.local} UseDevolution       : True DevolutionLevel     : 0 To get the settings on the remote server, use the CIM session parameter -Session.
$sess = New-CimSession -ComputerName Test1-Win2k16 Get-DnsClientGlobalSetting -Session $sess UseSuffixSearchList : True SuffixSearchList    : {labdomain.local} UseDevolution       : True DevolutionLevel     : 0 PSComputerName      : Test1-Win2k16  Get-DnsClientServerAddress
This cmdlet retrieves one or more DNS address associated with the interfaces on the computer. For example,
Example
Get-DnsClientServerAddress PS C:\Users\Administrator> Get-DnsClientServerAddress InterfaceAlias               Interface Address ServerAddresses                              Index     Family --------------               --------- ------- --------------- Ethernet0                            3 IPv4    {192.168.0.106} Ethernet0                            3 IPv6    {} Loopback Pseudo-Interface 1          1 IPv4    {} isatap.{5F9A3612-A410-440...         4 IPv4    {192.168.0.106} isatap.{5F9A3612-A410-440...         4 IPv6    {}  In the above output, the main interface Ethernet0 has associated DNS address is 192.168.0.106. Likewise, there are different IPv4 and IPv6 interfaces, and their DNS addresses are displayed in the Server Address field.
To retrieve only IPv4 interface associated DNS server address, use -AddressFamily parameter.
Get-DnsClientServerAddress -AddressFamily IPv4
Output
 InterfaceAlias               Interface Address ServerAddresses                              Index     Family --------------               --------- ------- --------------- Ethernet0                            3 IPv4    {192.168.0.106} Loopback Pseudo-Interface 1          1 IPv4    {} isatap.{5F9A3612-A410-440...         4 IPv4    {192.168.0.106} To get the DNS server IPs of the specific interface, you need to use its index by supplying index to the -InterfaceIndex Parameter.
Get-DnsClientServerAddress -InterfaceIndex 3 InterfaceAlias               Interface Address ServerAddresses                              Index     Family --------------               --------- ------- --------------- Ethernet0                            3 IPv4    {192.168.0.106} Ethernet0                            3 IPv6    {} To get the DNS server list on the remote system, you need to use the CIM session parameter -Session.
Get-DnsClientServerAddress -AddressFamily IPv4 -Session $sess
Output
InterfaceAlias               Interface Address ServerAddresses                              Index     Family --------------               --------- ------- --------------- Ethernet0                            3 IPv4    {192.168.0.106} Loopback Pseudo-Interface 1          1 IPv4    {} isatap.{5F9A3612-A410-440...         4 IPv4    {192.168.0.106}