This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Set-Dns Client Server Address

Sets DNS server addresses associated with the TCP/IP properties on an interface.

Description

The Set-DnsClientServerAddress cmdlet sets one or more IP addresses for DNS servers associated with an interface. This cmdlet statically adds DNS server addresses to the interface. If this cmdlet is used to add DNS servers to the interface, then the DNS servers will override any DHCP configuration for that interface.

Example 1: Set the DNS server addresses on an interface with a specified index value

This example sets the DNS server addresses on a specified interface with the index value of 12.

Example 2: Reset a DNS client to use the default DNS server addresses

This example resets the DNS client to use the default DNS server addresses specified by DHCP on the interface with an index value of 12.

Runs the cmdlet as a background job. Use this parameter to run commands that take a long time to complete.

The cmdlet immediately returns an object that represents the job and then displays the command prompt. You can continue to work in the session while the job completes. To manage the job, use the *-Job cmdlets. To get the job results, use the Receive-Job cmdlet.

For more information about Windows PowerShell background jobs, see about_Jobs .

-CimSession

Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.

Prompts you for confirmation before running the cmdlet.

-InputObject

Specifies the input to this cmdlet. You can use this parameter, or you can pipe the input to this cmdlet.

-InterfaceAlias

Specifies the friendly name of the interface.

-InterfaceIndex

Specifies the index number of the interface.

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.

-ResetServerAddresses

Resets the DNS server IP addresses to the default value.

-ServerAddresses

Specifies a list of DNS server IP addresses to set for the interface.

-ThrottleLimit

Specifies the maximum number of concurrent operations that can be established to run the cmdlet. If this parameter is omitted or a value of 0 is entered, then Windows PowerShell® calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies only to the current cmdlet, not to the session or to the computer.

Validates that one or more IP addresses are responsive DNS servers before the IP addresses are set to the interface. This parameter must be used with the ServerAddress parameter.

Shows what would happen if the cmdlet runs. The cmdlet is not run.

CimInstance

The Microsoft.Management.Infrastructure.CimInstance object is a wrapper class that displays Windows Management Instrumentation (WMI) objects. The path after the pound sign ( # ) provides the namespace and class name for the underlying WMI object.

The MSFT_DNSClientServerAddress class has the various DNS server IP addresses configured on a given interface. If no interface is specified, then all interfaces are configured.

Related Links

Submit and view feedback for

Additional resources

How to change DNS server using Command Prompt and PowerShell

How to change dns server using command prompt, how to change dns server using powershell, how to find dns servers used in windows 11, how do i know if my dns is working https.

TIP : Read more about some of the best DNS server providers – Comodo Secure DNS,   OpenDNS,   Google Public DNS,   Yandex Secure DNS,   Cloudflare DNS,   Angel DNS, etc.

[email protected]

How to change DNS to Google, Cloudflare, or OpenDNS on Windows 10

If you need to change your device's DNS addresses, in this guide, you'll learn three ways to perform this task on Windows 10.

Avatar for Mauro Huc

Domain Name System (DNS) is a service that translates familiar domain names (Google.com) into IP addresses (172.217.6.238) which aren’t easy to remember. You don’t usually have to worry about adjusting the DNS configuration because your Internet Service Provider (ISP) provides this service automatically. However, you will find many other DNS resolvers on the internet that are faster, reliable, private, and more secure, including those provided by Cloudflare , Google , and Cisco .

If the DNS servers offered by your ISP are slow and not reliable or don’t trust their resolvers, you can change the DNS addresses on Windows 10 in at least four different ways using Command Prompt, PowerShell, Settings, and Control Panel.

In this guide , you’ll learn how to change the DNS addresses to use a more reliable and secure resolution service on your Windows 10 device.

Best DNS servers for Windows 10

Change dns servers on windows 10 using command prompt, change dns servers on windows 10 using powershell, change dns servers on windows 10 using settings, change dns servers on windows 10 using control panel.

Although there are many resolver services out there, Cloudflare, Google, and OpenDNS are among the companies that offer fast, reliable, and secure resolvers.

Cloudflare DNS addresses

Google public dns addresses, opendns by cisco dns addresses.

Although using command lines is not a suitable method for most users, it’s one of the quickest ways to change the DNS address on Windows 10.

To change the DNS address with Command Prompt, use these steps:

Open Start on Windows 10.

Search for Command Prompt , right-click the top result, and select the Run as administrator option.

Type the following command to see your current networking configuration and press Enter :

Under the network adapter section, confirm the adapter’s name and these fields:

ipconfig view DNS info

Type the following command to set the new DNS server address and press Enter :

In the above command, make sure to change Ethernet1  with the name of your adapter and  1.1.1.1  with the DNS server address that you want to use.

Type the following command to set an alternate DNS server address and press Enter :

In the above command, make sure to change Ethernet1  with the name of your adapter and 1.0.0.1 with the preferred alternate DNS server address.

Change DNS IP on Windows 10

Once you complete the steps, you can confirm the new configuration using the ipconfig /all command and checking the DNS Servers’ addresses.

Microsoft is in the process of retiring netsh on Windows 10. It would be best to start using the NetTCPIP networking module available in PowerShell instead.

Windows 10 also includes PowerShell, a command-line platform that allows you to use the NetTCPIP module to manage networking settings, including the ability to change the DNS address settings of your device.

To change the DNS address with PowerShell, use these steps:

Open Start .

Search for PowerShell , right-click the result, and select the Run as administrator option.

Type the following command to view your current network configuration and press Enter :

After running the command, note the following information: 

PowerShell view network configuration

Type the following command to assign a primary DNS server address and press Enter :

Change primary DNS address

(Optional) If you need to set a secondary DNS server address, you can use the same command, but adding a comma and appending the second address:

Change primary and secondary DNS addresses

In the above command, make sure to change the InterfaceIndex number with the one corresponding to your adapter, and change ServerAddresses with the DNS IP address.

After you complete the steps, you can test the new configuration using this guide .

You can also specify new DNS addresses using the Settings app, but you need to configure all the TCP/IP settings to static to make it work. If you’re not comfortable assigning a static TCP/IP configuration , you should not use this option. 

To change the Windows 10 DNS address with Settings, use these steps:

Open Settings .

Click on Network & Internet .

Click on Status .

Under the “Network status” section, click the Properties button for the network you want to modify.

Under the “IP settings” section, click the Edit button.

IP settings edit option

Use the drop-down menu and select the Manual option.

Turn on the IPv4 toggle switch.

Under the “IP address” section, specify the TCP/IP address for the computer.

Under the “Subnet prefix length” section, set the subnet length. Usually, for home networks, the address length is 24 to represent the subnet address 255.255.255.0.

Under the “Gateway” section, set the default gateway address. Usually, this is the IP address of the router.

Under the “Preferred DNS” section, specify the IP address of the DNS server (for example, 1.1.1.1).

Network settings change DNS

Under the “Alternate DNS” section, specify the IP address of the secondary DNS address.

Click the Save button.

Once you complete the steps, the device will continue to receive its TCP/IP address from the DHCP server, but it’ll now use the specified DNS addresses.

Alternatively, you can also use Control Panel to change the DNS settings on Windows 10.

To change the DNS address of Windows 10 with Control Panel, use these steps:

Open Control Panel .

Click on Network and Internet .

Click on  Network and Sharing Center .

Click the Change adapter settings option from the left pane.

Change adapter settings on Windows 10

Right-click the network adapter and select the Properties option.

Select the Internet Protocol Version 4 (TCP/IPv4) option.

Click the Properties button.

Control Panel change IPv4 settintgs

Under the “Use the following DNS server addresses” section, set Preferred DNS server , which is the server’s IP address providing DNS resolutions (for example, 8.8.8.8 ).

Windows 10 change DNS IP in Control Panel

(Optional) Set the Alternative DNS server , the DNS address that your device will use if it can’t reach the preferred server address.

Click the  OK button.

Click the  Close  button.

Once you complete the steps, you can open your web browser and try loading a website to see if the new configuration works.

Whatever method you use, make sure the IP address for the DNS server is correct to allow proper resolution. Otherwise, you won’t be able to connect to the internet.

Although we’re focusing this guide on Windows 10, you can use the Command Prompt and Control Panel methods on Windows 8.1 and Windows 7.

We hate spam as much as you! Unsubscribe any time Powered by follow.it ( Privacy ), our Privacy .

Press ESC to close

How to set primary and secondary dns server addresses with powershell.

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.

Set-DnsClientServerAddress

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:

Get-NetAdapter

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

Get-DnsClientServerAddress

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: https://docs.microsoft.com/en-us/powershell/module/dnsclient/set-dnsclientserveraddress?view=win10-ps

Was this article useful? Support my work!

Share Article:

Jorge bernhardt, how to rename a computer with powershell, how to create a storage pool using powershell.

JOIN OUR LIVE DEMO WEBINAR

This wednesday | 12 pm est / 9 am pst, how to change dns address remotely with powershell, may 10, 2019, by peter barnett, table of contents:, what version of windows server do you need to use 100 new commands, familiarity with powershell command blocks: get and add, simple script to set the dns server ip addresses on a network card based on its name, change dns address remotely with action1 rmm.

Betweentimes you need to update multiple computers with DNS settings. Instead of doing this one by one manually you can automate it so it can be done in one go, from a plain   PowerShell script. It’s simple but very effective. This article shows how to remotely change DNS settings.

If you are administering DNS on Windows Server systems, you may have heard about Dnscmd, a powerful command-line tool that allows you to perform almost any DNS management task. Without detracting from the merits of Dnscmd, I am pleased to announce that now DNS administrators have gained a new support group in the face of 100 PowerShell teams. In this article I will talk about three of them, and also give an example of how one simple powerful tool of PowerShell can be made even more powerful.

1. What Version of Windows Server Do You Need to Use 100 New Commands

I have not had time to try out the entire hundred, but, as far as I can tell, to use them with respect to Windows Server 2008 R2, it is enough to have a Windows 8 workstation that is joined to the domain and on which the remote server administration tools (RSAT) for Windows 8. To display a list of 100 DNS commands, use the following command:

get-command *-dnsserver*

If you are running Windows Server 2012, then simply install the built-in DNS management tools, and the DNS commands will be at your disposal.

2. Familiarity with PowerShell Command Blocks: Get and Add

As you probably already understood, familiarity with the blocks of PowerShell commands should begin with testing the   Get-   commands.   Get-dnsserveredns   gives information about whether the DNS server has DNS extensions enabled (I have enabled). Get-dnsserverrecursion lets you know if a server is accepting DNS requests for zones that do not exist on this server. Suppose I request from a local DNS server serving AD, the resource www.microsoft.com. The local DNS server does not work with the public Microsoft zone, and it will perform requests to Internet resources only after recursion is enabled.

Why is this feature useful? Unfortunately, in recent years, the number of attempts to use DNS servers to organize malicious distributed denial of service (DoS) attacks has greatly increased, forcing administrators to disable recursion on DNS servers (it is enabled by default). In such cases, it is useful to be able to verify this DNS server or use the excellent means of remoting PowerShell. For example, if there are five DNS servers D1, D2, D3, D4 and D5, then a simple report on their recursion status can be displayed using the command:

invoke-command -computername d1,d2,d3,d4,d5 -scriptblock {get-dnsserverrecursion|select pscomputername,enable}

We know that the – scriptblock   parameter allows braces to give remote computers a command that should be executed. In this case, there is a DNS command in curly braces, followed by a   Select   statement with the name of the computer on which to run this command, as well as the result.

In Server 2012, one of the time-saving DNS commands is   add-dnssecondaryzone . I discovered it by setting up a new DNS server as a secondary server for a specific group of DNS zones. Setting up a secondary DNS server for an existing domain using a graphical interface or Dnscmd is a trivial task. As it turned out, you can configure the secondary DNS server for the bigfirm.com domain with the main IP address 71.23.1.5 and save the zone data to a text file bigfirm.com.dns using the following command:

add-dnssecondaryzone bigfirm.com “bigfirm.com.dns” 71.23.1.5

I assumed that this could be done immediately with seven domains, for which it would be enough just to change the name of the zone in two places. First, I saved the domain names into an array, which is a comma-separated list of names in quotes:

$zones=“bigfirm.com”,“minasi.com”,“mmco.com”,“pungogrill.com”,“thesoftwareconspiracy.com”,“softwareconspiracy.com”,“steadierstate.com”

Then, using the pipeline and the   foreach-object   command, I organized the transfer of the name of each zone to the   add-dnssecondaryzone   command using the built-in variable   $ _ , the contents of which is what is currently in the pipeline:

$zones | foreach-object {Add-DnsServerSecondaryZone $_ $_+“.dns” “71.23.1.5”}

It worked right away.

3. Example of Simple Script to Set the DNS Server IP Addresses on a Network Card Based on Its Name

Click Start, type PowerShell, and then click Windows PowerShell.

Step to Change DNS Settings is to Run PowerShell as Administrator

4. Change DNS Address Remotely with Action1 RMM

Action1’s intuitive dashboard helps optimize routine tasks, significantly scaling up IT productivity.

Step 1:  After logging into the Action1 dashboard, in the  Navigation   pane (the left column), select  Managed Endpoints and mark the endpoint to change DNS remotely.

managed endpoints kb

Step 2:  Then click on the   More Actions  menu and select  Run   Script.

change dns ip address powershell

Step 3: Choose Script language and type this command to change DNS:

interface ip set dns "interface_name" static DNS_address

change dns ip address powershell

Step 4:  In the  Select Managed Endpoints window, you mark those endpoints on which you are going to change DNS. You can add all the available endpoints or mark them one by one. 

Creating a reboot policy - step 2

Step 5: Schedule   the action ( Run now/ No schedule yet/ At specific time/ Repeat )   and  Finish .

schedule and finish kb

See What You Can Do with Action1

Join our weekly LIVE demo “Risk-based Patch Management with Action1” to learn more

about Action1 features and use cases for your IT needs.

spiceworks logo

Related Posts

Preventing windows 10 upgrade to windows 11.

Jan 24, 2023 | How-to Articles

Action1 simplifies many patch management tasks, including upgrades to Windows 11. However, some of our customers still want to keep Windows 10 for several good reasons, such as...

Sophos Endpoint Agent Silent Installation Challenges

Jan 17, 2023 | How-to Articles

Action1 supports dozens of pre-packaged apps out of the box via our App Store, and it also allows authorizing of your own custom apps. Adding your custom apps sometimes is quite...

Finding All LastPass Instances Installed as Google Chrome Extensions

Jan 3, 2023 | How-to Articles

After the recent major security breach at LastPass, this question started coming up more and more often: how do I find all the installs of LastPass on my users' computers? Some...

Data Structure

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,

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.

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.

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.

change dns ip address powershell

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

change dns ip address powershell

To get the same settings on the remote server, we can use the - CimSession parameter.

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.

To get the settings on the remote server, use the CIM session parameter - Session .

This cmdlet retrieves one or more DNS address associated with the interfaces on the computer. For example,

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.

To get the DNS server IPs of the specific interface, you need to use its index by supplying index to the - InterfaceIndex Parameter.

To get the DNS server list on the remote system, you need to use the CIM session parameter - Session.

Chirag Nagrekar

0 Followers

Tutorials Point

Set IP address with PowerShell

How to Change Your IP Address in Windows Using PowerShell

You may know how to change the IP address via the GUI. It's pretty simple. Just go to Control Panel > Network and Internet, select the IPv4 properties and change the IP address. The whole process takes about a minute. But what if you have to do this on multiple systems and repeat all these steps several times? Then it becomes really annoying. With PowerShell, you can easily do this tedious task.

PowerShell may sound difficult and you may be hesitant to work with it, but it has some unique features.

With PowerShell, you can gather information, change system settings and automate almost everything in Windows. It is more powerful than Cmd and offers more flexibility. Tasks done with PowerShell can not only automate but also save you time.

To open PowerShell, type PowerShell in the search bar of your Windows 10 computer and then press Ctrl+Shift+Enter to launch it with administrator privileges.

To see the current IP configuration, type Get-NetIPAddress in PowerShell

Get-NetIPAddress gives IP address information with prefix length and address family.

Get current IP address in PowerShell

Alternatively, you can type Get-NetIPConfiguration to get some advanced details. It gives IP address information along with its default gateway, DNS information, and Interface index.

From Get-NetIPConfiguration Result, note down the index number of the adapter for which you want to change IP address.

Use Get-NetIPConfiguration on Windows

To specifically get the Interface index, type

in PowerShell:

PowerShell Get-NetAdapter command

Set a new IP address using PowerShell

All of the above commands are used to view current configurations. To set a new IP address, execute below command. Replace xxx.xxx.xxx.xxx with your own IP address.

Suppose we have the following required configurations:

Replace the command parameters with your own addresses.

Note that the prefix length specifies the subnet mask of IP address.

Set IP address using PowerShell

Set a New DNS Servers Address

Up till now, we have configured IP address, subnet mask, and Default-gateway successfully. Now one thing is missing which is the DNS server address. to set a new DNS server address, type the command with the below syntax.

Replace xxx.xxx.xxx.xxx with your required primary and secondary DNS server addresses.

Set DNS server address using PowerShell

As you can see, it is relatively straightforward to configure TCP/IP through PowerShell. The techniques that I have shown you tend to be most useful when you need to configure multiple machines.

Last Updated on June 12, 2022 by FAQForge

Set-DnsClientServerAddress

The Set-DnsClientServerAddress cmdlet sets one or more IP addresses for DNS servers associated with an interface. This cmdlet statically adds DNS server addresses to the interface. If this cmdlet is used to add DNS servers to the interface, then the DNS servers will override any DHCP configuration for that interface.

-CimSession [<CimSession[]>]

Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.

-InterfaceAlias <String[]>

Specifies the friendly name of the interface.

-InterfaceIndex <UInt32[]>

Specifies the index number of the interface.

-PassThru [<SwitchParameter>]

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.

-ResetServerAddresses [<SwitchParameter>]

Resets the DNS server IP addresses to the default value.

-ServerAddresses [<String[]>]

Specifies a list of DNS server IP addresses to set for the interface.

-ThrottleLimit [<Int32>]

Specifies the maximum number of concurrent operations that can be established to run the cmdlet. If this parameter is omitted or a value of 0 is entered, then Windows PowerShellr calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies only to the current cmdlet, not to the session or to the computer.

-Validate [<SwitchParameter>]

Validates that one or more IP addresses are responsive DNS servers before the IP addresses are set to the interface. This parameter must be used with the ServerAddress parameter.

-Confirm [<SwitchParameter>]

Prompts you for confirmation before running the cmdlet.Prompts you for confirmation before running the cmdlet.

-WhatIf [<SwitchParameter>]

Shows what would happen if the cmdlet runs. The cmdlet is not run.Shows what would happen if the cmdlet runs. The cmdlet is not run.

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

This example sets the DNS server addresses on a specified interface with the index value of 12.

This example resets the DNS client to use the default DNS server addresses specified by DHCP on the interface with an index value of 12.

This work is licensed under a Creative Commons Attribution 4.0 International. It is attributed to Microsoft Corporation and can be found here .

Think PowerShell

PowerShell for IT Pros

Change DNS Servers for Computers with Static IP Addresses

Aaron Rothstein · Mar 27, 2017 · 8 Comments

DNS Server Settings Screenshot

Easily change DNS servers for computers with static IP addresses using PowerShell. Run locally or remote.

Changing DNS servers

Recently I provisioned new domain controllers as part of a migration from a 2008 R2 Active Directory forest to a 2016 Active Directory forest. Like the existing 2008 R2 domain controllers, the new domain controllers are configured as AD integrated DNS servers and will be the primary and secondary DNS servers used on the internal network.

Changing DNS servers for clients using DHCP is a trivial matter; just update Option 6 for the DHCP scope with the new name server IP addresses and restart the client (or wait until they renew their lease).

However if you are like a lot of environments, you have Windows servers and maybe even workstations configured with static IP addresses and static DNS servers. How can you systematically update these configurations?

Change DNS servers with Win32_NetworkAdapterConfiguration

We can use PowerShell and Get-WmiInstance or Get-CimInstance (Win 8/2012 or later). For compatibility, we will be demonstrating using Get-WmiInstance .

In our scenario, our old DNS servers were 192.168.1.11 and 192.168.1.12. We will be replacing these with 192.168.1.13 and 192.168.1.14. We use the following snippet leveraging the class Win32_NetworkAdapterConfiguration to return a list of all non-DHCP adapters with DNS servers configured.

To see the current DNS servers, we run the following:

To update the DNS servers for adapters meeting this criteria, we run the following:

To confirm the servers have been updated, re-run our original Get sequence:

Remotely updating DNS servers for set of computers

The previous section covered the basic updating of the DNS servers locally on a single computer. However you may have the need to update multiple computers remotely.

One approach would be to query your Active Directory to get a list of all computers that have statically assigned IP addresses. For example, it may be that all of your computers running a Windows Server OS have static IPs.

Get all “Windows Server” AD computers

We can get all of the the computers in Active Directory that are running a “Windows Server” build using the following Get-ADComputer  query:

Use Invoke-Command to update DNS on remote computers

We now have a set of computers to process. We will use Invoke-Command to connect via WinRM to the remote computer and execute the previous commands locally on the computer.

Why we used Invoke-Command

We could use the WMI cmdlets directly against the remote computer, but it would require all of the necessary network port access and permissions for using WMI remotely. Connecting using WinRM only requires a single network port to be opened and lets us run all other cmdlets without having to give a lot of thought to remote security and performance over the network.

Set-DnsClientServerAddress: Windows 8/2012 or newer

The method described above is intended for maximum compatibility: it will work with Windows Server 2003 all the way through Windows Server 2016. If however your environment is running Windows 8 / Windows Server 2012  and above, you do not need to use the WMI cmdlets, you can use the newer cmdlet Set-DnsClientServerAddress .

Note that we specified the InterfaceIndex . Other interface identification options are InterfaceAlias or you can pass a CimInstance for an interface to the cmdlet. You could use this cmdlet in hybrid with our previous Get-WmiObject query:

Using this approach as a starting point, you can modify as required fit your own environment’s requirements to confidently and efficiently update DNS servers for computers with statically assigned IPs.

Reader Interactions

' src=

March 27, 2017 at 7:42 pm

For big companies this is likely to fail on older computers — and they are still likely to be around.

Fall back to NetSh, it’s on almost everything and PowerShell can drive it easily enough.

' src=

March 28, 2017 at 7:37 am

This method will work for Windows XP / 2003 computers if they have WMF installed and configured. You are right though, anything older than that and you will have to resort to legacy tool sets.

' src=

December 24, 2019 at 11:20 am

I am new to PowerShell and Windows DC’s but I need help simply changing the DC static IP to another Static IP. It seems you are using DHCP here and I don’t think that will work. In my use-case I am moving a DC from one environment to another. I need to be able to apply the changes remotely. Using Infrastructure as code (IaC) e.g. aws CloudFormation.

March 7, 2020 at 2:12 pm

Hey Mike, I’m guessing you have already addressed your issue, but for changing the IP address of a host (DC or otherwise), you would use the cmdlet Set-NetIPAddress ( https://docs.microsoft.com/en-us/powershell/module/nettcpip/set-netipaddress?view=win10-ps ).

For a domain controller, here are additional recommended steps from a TechNet article that is no longer available: “After you change the IP address of a domain controller, you should run the ipconfig /registerdns command to register the host record and dcdiag /fix command to ensure that service records are appropriately registered with DNS”

' src=

June 11, 2020 at 4:13 pm

Good afternoon,

I have been trying to turn part of this into a script that I can setup in Group Policy and push out network wide, but I am having trouble.

The part I am using is: $NewDnsServerSearchOrder = “192.168.1.13”,”192.168.1.14″

$Adapters | ForEach-Object {$_.SetDNSServerSearchOrder($NewDnsServerSearchOrder)} | Out-Null

Whenever I try to run it in PS ISE I get the following error: “You cannot call a method on a null-valued expression”

I am not sure what I am doing wrong here because it runs perfectly fine in a PS window. Any Suggestions?

June 13, 2020 at 9:28 am

Hi Greg, Replying here as well, we can continue the conversation either on Facebook or here, whichever you prefer.

It appears $Adapters is null. Can you confirm nothing is being returned when running the following in the ISE: Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DHCPEnabled -ne ‘True’ -and $_.DNSServerSearchOrder -ne $null}

' src=

October 7, 2020 at 3:09 pm

I am not a PS expert – How would the above scripts work on servers that have multiple NICs in various VLANs if I only want to change DNS on a specific NIC? And are there arguments to provide credentials if I am remotely acting on servers requiring different administrative credentials for making these modifications?

December 20, 2020 at 12:26 am

You would want to look at doing some additional filtering during the initial querying, under the ‘Where-Object’ call. For example, you could query by adapter name or other properties: $Adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DHCPEnabled -ne ‘True’ -and $_.DNSServerSearchOrder -ne $null}

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Easy365Manager

How To Safely Change DNS Client Settings

DNS Client Settings PowerShell

Picture the following scenario:

How do you SAFELY and EASILY change the DNS settings of all your servers?

PowerShell Automation

The answer to this question is of course PowerShell. If you have a large number of servers you’ll want to automate this process.

However, things can quickly go bad if you’re not careful with this. Messing up your server DNS settings can practically blow up your environment.

Working with a client facing exactly this challenge we came up with the following script:

The script takes an input file named “DNS_Clients_HostNames.txt”. The input files should have a header (first line) named “Hostname”, similar to this:

One thing to notice about the script is that line 11 is commented out – this is the line that actually changes the DNS settings of the server.

This is done as an extra precaution to allow you to evaluate the script output before making any live changes.

Once you’ve tested the output of the script you can un-comment line 11 to allow the script to perform the actual changes on your servers DNS client settings.

Another safety measure would be to limit your input file to only a few servers. Check the servers manually after running the script. If all looks fine you can extend the input file to your full list of servers.

When you have run the script and changed all your servers, you can use the same script to check that all servers are now being skipped by the script. This indicates that DNS client settings has changed, since no adapter is now found with the old DNS server settings.

Hope you can use the script, perhaps as inspiration to your own approach. Use at own risk 😉

IMAGES

  1. How to Change Your IP Address Using PowerShell

    change dns ip address powershell

  2. How to change DNS address to faster resolvers on Windows 10 • Pureinfotech

    change dns ip address powershell

  3. vGeek: Powershell: Change DNS ip addressess remotely on multiple computers

    change dns ip address powershell

  4. How to Change DNS Server Using PowerShell?

    change dns ip address powershell

  5. Device disconnects from Windows 10 hotspot & fails to reconnect

    change dns ip address powershell

  6. How to Change Your IP Address in Windows Using PowerShell

    change dns ip address powershell

VIDEO

  1. PowerShell Basics

  2. change DNS settings on Windows 11 Computer

  3. How to configure Secondary DNS and Stub DNS server

  4. How to Change Your Default DNS to Google DNS for Fast Internet

  5. How to Properly Set Up No-IP DNS Service Provider

  6. how to add alternative ip address into Windows Server?

COMMENTS

  1. Set-DnsClientServerAddress (DnsClient)

    The Set-DnsClientServerAddress cmdlet sets one or more IP addresses for DNS servers associated with an interface. This cmdlet statically adds DNS server

  2. How to change DNS server using Command Prompt and PowerShell

    How to change DNS server using PowerShell · Search for powershell in the Taskbar search box. · Click the Run as Administrator option. · Enter the

  3. How to change DNS to Google, Cloudflare, or OpenDNS on

    To change Windows 10 DNS settings, use netsh set DNS command on CMD, or Set-DnsClientServerAddress on PowerShell, open IPv4 properties in

  4. How to set primary and secondary DNS server addresses with

    How to set primary and secondary DNS server addresses with PowerShell · Get-NetAdapter | Select-Object InterfaceAlias , InterfaceIndex · Get-

  5. How to Change DNS Address Remotely with PowerShell

    Betweentimes you need to update multiple computers with DNS settings. Instead of doing this one by one manually you can automate it so it

  6. How to get DNS IP Settings using PowerShell

    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

  7. How to Change Your IP Address in Windows Using PowerShell

    You may know how to change the IP address via the GUI. It's pretty simple. Just go to Control Panel > Network and Internet, select the IPv4

  8. Set-DnsClientServerAddress

    The Set-DnsClientServerAddress cmdlet sets one or more IP addresses for DNS servers associated with an interface. This cmdlet statically adds DNS server

  9. Change DNS Servers for Computers with Static IP Addresses

    Easily change DNS servers for computers with static IP addresses using PowerShell. Run locally or remote. Changing DNS servers. Recently I

  10. How To Safely Change DNS Client Settings

    Need to change DNS client settings remotely in bulk? Use PowerShell to identify and change systems with old DNS settings.