Solved

Change IP address with netsh without knowing the interface name.

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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 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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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