Solved

Change IP address with netsh without knowing the interface name.

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 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