Solved

Change IP address with netsh without knowing the interface name.

Posted on 2011-09-20
4
314 Views
Last Modified: 2014-05-15
I am looking to run a batch file on about 100 Server 2003 machines.  One task is to change a known static ip address of an unknown nic.  There are at least two other nics present on these machines and the interface names are inconsistent.  


Here's the relevant portion of my batch file:
set ipAdrs=192.168.1.15
set subMsk=255.255.255.0
netsh int ip set address name = "%LAN%" source = static addr = %ipAdrs% mask = %subMsk%

How can I get %LAN%?
0
Comment
Question by:zeabo66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 36570943
Hi there, you can try this VBS code.  I suggest you try it on a test machine, just in case...

Regards,

Rob.
strOldIP = "192.168.1.92"
strNewIP = "192.168.1.15"
strNewSubnet = "255.255.255.0"

strComputer = "."
blnFound = False
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select Caption,IPAddress From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
	For Each objIP In objItem.IPAddress
		If strOldIP = objIP Then
			blnFound = True
			strCaption = objItem.Caption
			objItem.EnableStatic Array(strNewIP), Array(strNewSubnet)
		End If
	Next
Next
If blnFound = False Then
	WScript.Echo "Unable to find adapter with IP Address of " & strOldIP
Else
	WScript.Echo strCaption & " was updated."
End If

Open in new window

0
 
LVL 2

Expert Comment

by:GoatCreek
ID: 38563485
Use powershell

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Format-Table -Property IPAddress, servicename

Open in new window


Where servicename is het nic name.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question