Batch file to change DNS.

Cyrus Hosmer 0 Reputation points
2023-09-12T17:18:39.1766667+00:00

Sorry if about the tags, it would not let me ask the question without adding them.

I wanted to create a .bat file that I can run on our workstations.

It needs to ask for elevation since the commands I am executing need admin rights.

I want to check the current DNS settings with ipconfig /all then be able to select between these two commands:

netsh interface ipv4 add dns "Ethernet" 10.100.0.11 index=2

netsh interface ipv4 add dns "Ethernet 2" 10.100.0.11 index=2

then run ipconfig /all again to verify the change.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,664 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,770 questions
Azure Batch
Azure Batch
An Azure service that provides cloud-scale job scheduling and compute management.
303 questions
Windows 10 Network
Windows 10 Network
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Network: A group of devices that communicate either wirelessly or via a physical connection.
2,274 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. チャブーン 396 Reputation points MVP
    2023-09-12T17:30:56.6333333+00:00

    Hi, Cyrus Hosmer

    This is Chaboon.

    Wouldn't it be better to try using powershell instead of a bat file?

    And you use Startup Script via Group Policy, the command execute Administrative privileges.

    See below the article (see Example1)
    https://learn.microsoft.com/en-us/powershell/module/dnsclient/set-dnsclientserveraddress?view=windowsserver2022-ps

    You can use the InterfaceAlias option instead of the InterfaceIndex option.
    The InterfaceAlias ​​option allows you to specify a network friendly name (for example, Ethernet 1) instead of an index number.

    0 comments No comments