Solved

Change IP address with netsh without knowing the interface name.

Posted on 2011-09-20
4
282 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now