In this post, I want to show how to configure your computer’s primary and secondary DNS server using PowerShell. In this case, we will use the Set-DnsClientServerAddress cmdlet.


The workaround in a local computer:

The Get-NetAdapter cmdlet obtains the basic properties of the network adapter. with this cmdlet, we get the index of the network adapter, among other data. Run the following PowerShell command as an administrator:


The Get-DnsClientServerAddress cmdlet gets one or more DNS server IP addresses associated with the interfaces on the computer.


To set the DNS servers addresses using PowerShell, use Set-DnsClientServerAddress with the following syntax.

Important: Run the following PowerShell command as Administrator:

The Set-DnsClientServerAddress sets the DNS server addresses on an interface using a specified index value.

DNS PowerShell

The workaround in a remote computer:

The Enter-PSSession cmdlet starts an interactive session with a single remote computer.

The commands that you type run on the remote computer during the session.

DNS PowerShell

If you want to know more about Set-DnsClientServerAddress cmdlet, check out this link: