« Finding a decent Pencil SharpenerDell Laptop Slow / Lagging / Delayed Keyboard Response »

HOWTO: Remotely Change Windows Static IP to DHCP


Permalink 06:25:10 pm by guy, Categories: Windows

Recently I had several PCs at work that had been setup with Static IP addresses. I wanted to change them from Static to DHCP for ease of management. This is the batch script that I came up with to do this remotely. I’m sure that there are many ways to do this, but this seems to work well. This can be tricky though. Remember, this should work quite well based on my exprience, but if this script is executed remotely and fails you may be taking a walk to go fix it. We are manipulating the network address after all!

Although the netsh commands that I use in the script can be executed remotely through remote netsh commands, I chose to execute this script ON the remote PC by using the PSExec tool. That way, when the netsh commands are completed the script will continue executing and execute a IPConfig /renew command to initiate the DHCP update even though the network connection will be disrupted during the command execution.

I include the command to execute this below, but here it is for clarity. Assuming that you name the file containing the script below setdhcpclient.bat:
psexec \\ -d -c setdhcpclient.bat

REM SetDHCPClient.bat
REM Script to convert a static client to a dhcp client.
REM Note that you would have to also create a DHCP
REM reservation if you want to keep the same address.
REM That process would be done separately from this.
REM execute this script remotely using PSEXEC
REM Example command line for PSEXEC:
REM PSEXEC \\ -d -c setdhcpclient.bat
netsh interface ip set dns "Local Area Connection" dhcp
netsh interface ip set wins "Local Area Connection" dhcp
netsh interface ip set address "Local Area Connection" dhcp
ipconfig /renew

This script is far from perfect but it did fulfull my needs. One potential issue you may run into is that your network interface may not be named “Local Area Connection". I’m not sure how this would fail in that case. Anybody have some improvements or alternative methods?

July 2019
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
I'm a generalist, at least if I'm honest. In my job I am primarily a developer, but also a sysadmin, and (as little as possible) technical support. I know a little about a lot of things, a lot about some things, and everything about nothing. Here I will post random learnings...


XML Feeds

User tools

powered by b2evolution