Solved

Change IP address with netsh without knowing the interface name.

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 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

22 Experts available now in Live!

Get 1:1 Help Now