Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - How can I change IP Adapters WITHOUT knowing exactly what thedescription is?

Reply
 
Old 06-02-2009   #1 (permalink)
GBPackerBacker


 
 

How can I change IP Adapters WITHOUT knowing exactly what thedescription is?

Hi all, I have a script that I use to chane an ip adapter according to
it's Description. I just got handed a task however, to run point on a
600 server migration where all, and I mean ALL servers need to be
reconfigured. I'd like to change my script so that it'll always set
the first adapter to a specific IP addess, then set the second one to
another. For example, Nic1 will always be the IP of the server used
for everyday activities, Nic2 will always be the backup network for
our corporate backup system. Problem is, there is a hodge podge of
server brands and Nic manufactures so I don't have consistant hardware
througout.

I'm not a guru by any means so I'm not sure which classes to use for
this or even to go about finding it. My current script is below, if
anyone can point me in the right direction on how to do this, I'd very
much appriciate it!

One other tidbit, but i will be pulling the new IP's from a text file
for the new configurations.

sIPAddress = "192.168.x.x"
sSubnetMask = "255.255.255.0"
sGateway = "192.168.x.x"
sDNS1 = "192.168.x.x"
sDNS2 = "192.168.x.x"

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where Description =
" & _
"'Broadcom NetXtreme 57xx Gigabit Controller - Packet Scheduler
Miniport'")

For Each objNetAdapter in colNetAdapters

arrDNSServers = Array("sDNS1", "sDNS2")
objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
Next

arrIPAddress = Array(sIPAddress)
arrSubnetMask = Array(sSubnetMask)
arrGateway = Array(sGateway)
arrGatewayMetric = Array(1)

For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(arrIPAddress, arrSubnetMask)
errGateways = objNetAdapter.SetGateways(arrGateway, arrGatewaymetric)

If errEnable = 0 Then
WScript.Echo "IP Address Change was successful"
Else
WScript.Echo "The IP address could not be changed."
End If
Next

My System SpecsSystem Spec
Old 06-02-2009   #2 (permalink)
just say NO to PDF


 
 

Re: How can I change IP Adapters WITHOUT knowing exactly what the description is?


"GBPackerBacker" <gbpackerbacker@xxxxxx> wrote in message
news:ac6ece34-f1d8-4c10-8d8e-22d00b7041d1@xxxxxx
Quote:

> Hi all, I have a script that I use to chane an ip adapter according to
> it's Description. I just got handed a task however, to run point on a
> 600 server migration where all, and I mean ALL servers need to be
> reconfigured. I'd like to change my script so that it'll always set
> the first adapter to a specific IP addess, then set the second one to
> another. For example, Nic1 will always be the IP of the server used
> for everyday activities, Nic2 will always be the backup network for
> our corporate backup system. Problem is, there is a hodge podge of
> server brands and Nic manufactures so I don't have consistant hardware
> througout.
>
> I'm not a guru by any means so I'm not sure which classes to use for
> this or even to go about finding it. My current script is below, if
> anyone can point me in the right direction on how to do this, I'd very
> much appriciate it!
>
> One other tidbit, but i will be pulling the new IP's from a text file
> for the new configurations.
>
> sIPAddress = "192.168.x.x"
> sSubnetMask = "255.255.255.0"
> sGateway = "192.168.x.x"
> sDNS1 = "192.168.x.x"
> sDNS2 = "192.168.x.x"
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colNetAdapters = objWMIService.ExecQuery _
> ("Select * from Win32_NetworkAdapterConfiguration Where Description =
> " & _
> "'Broadcom NetXtreme 57xx Gigabit Controller - Packet Scheduler
> Miniport'")
>
> For Each objNetAdapter in colNetAdapters
>
> arrDNSServers = Array("sDNS1", "sDNS2")
> objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
> Next
>
> arrIPAddress = Array(sIPAddress)
> arrSubnetMask = Array(sSubnetMask)
> arrGateway = Array(sGateway)
> arrGatewayMetric = Array(1)
>
> For Each objNetAdapter in colNetAdapters
> errEnable = objNetAdapter.EnableStatic(arrIPAddress, arrSubnetMask)
> errGateways = objNetAdapter.SetGateways(arrGateway, arrGatewaymetric)
>
> If errEnable = 0 Then
> WScript.Echo "IP Address Change was successful"
> Else
> WScript.Echo "The IP address could not be changed."
> End If
> Next
This can be a problem; there are a TON of network adapters.
My strategy was to first go through the collection of
Win32_NetworkAdapter...
You will have to write your own "Push" Subroutine and AMatch Function...

Set c_Collection = o_WMISVC.InstancesOf ( "Win32_NetworkAdapter")

For Each o_Instance in c_Collection
' get the adapter type
If o_Instance.AdapterType = "Ethernet 802.3" Then
If Len ( o_Instance.MACAddress) > 16 Then
If o_Instance.Availability = 3 Then
' this looks for logical vs physical adapters
If InStr ( 1, o_Instance.Description, "Miniport",
vbTextCompare) = 0 _
AND InStr ( 1, o_Instance.Description, "Bluetooth",
vbTextCompare) = 0 Then
If NOT IsNull ( o_Instance.Installed) Then
If o_Instance.Installed Then
If o_Instance.ConfigManagerErrorCode = 0
Then
' This is a valid adapter!
Push o_Instance.DeviceID,
a_ValidIndexes
End If
End If
End If
End If
End If
End If
End If
Next ' instance of Win32_NetworkAdapter

oLog.WriteLine "Intermediate list of valid adapters: " & Join (
a_ValidIndexes, ", ")
Set c_Collection = o_WMISVC.InstancesOf (
"Win32_NetworkAdapterConfiguration")

' there are usually many adapters; not all are enabled
For Each o_Instance in c_Collection
' look for matching index
If InArray ( o_Instance.Index. a_Indexes) >= 0 Then
' is a valid MAC address? (repeat)
If Len ( o_Instance.MACAddress) > 16 Then
' valid gateway configured?
If Len ( o_Instance.DefaultIPGateway) > 6 Then
' usually an array; converted to string
If Len ( Split ( o_Instance.DNSServerSearchOrder,
",")) > 6 Then
' then if IP is enabled
If o_Instance.IPEnabled Then
' finally, is a valid IP address? (may be
array converted to string)
If Len ( If Len ( SPlit (
o_Instance.IPAddress, ",")) > 6 Then
' Do the happy dance!
End If
End If
End If
End If
End If
End If
Next ' instance of Win32_NetworkAdapterConfiguration

HTH
--Maarten


My System SpecsSystem Spec
Old 06-05-2009   #3 (permalink)
just say NO to PDF


 
 

Re: How can I change IP Adapters WITHOUT knowing exactly what the description is?

Oops!
Corrected code...

This can be a problem; there are a TON of network adapters.
My strategy was to first go through the collection of
Win32_NetworkAdapter...
(You will have to write your own "Push" Subroutine and "InArray" Function)

Quote:

> Set c_Collection = o_WMISVC.InstancesOf ( "Win32_NetworkAdapter")
>
> For Each o_Instance in c_Collection
> ' get the adapter type
> If o_Instance.AdapterType = "Ethernet 802.3" Then
> If Len ( o_Instance.MACAddress) > 16 Then
> If o_Instance.Availability = 3 Then
> ' this looks for logical vs physical adapters
> If InStr ( 1, o_Instance.Description, "Miniport",
> vbTextCompare) = 0 _
> AND InStr ( 1, o_Instance.Description, "Bluetooth",
> vbTextCompare) = 0 Then
> If NOT IsNull ( o_Instance.Installed) Then
> If o_Instance.Installed Then
> If o_Instance.ConfigManagerErrorCode =
> 0 Then
> ' This is a valid adapter!
> Push o_Instance.DeviceID,
> a_ValidIndexes
> End If
> End If
> End If
> End If
> End If
> End If
> End If
> Next ' instance of Win32_NetworkAdapter
>
> oLog.WriteLine "Intermediate list of valid adapters: " & Join (
> a_ValidIndexes, ", ")
> Set c_Collection = o_WMISVC.InstancesOf (
> "Win32_NetworkAdapterConfiguration")
>
> ' there are usually many adapters; not all are enabled
> For Each o_Instance in c_Collection
> ' look for matching index
> If InArray ( o_Instance.Index. a_Indexes) >= 0 Then
> ' is a valid MAC address? (repeat)
> If Len ( o_Instance.MACAddress) > 16 Then
> ' valid gateway configured?
> If Len ( o_Instance.DefaultIPGateway) > 6 Then
> ' usually an array; converted to string
> If Len ( Split ( o_Instance.DNSServerSearchOrder,
> ",")) > 6 Then
> ' then if IP is enabled
> If o_Instance.IPEnabled Then
> ' finally, is a valid IP address? (may be
> array converted to string)
> If Len ( SPlit ( o_Instance.IPAddress,
> ",")) > 6 Then
> ' Do the happy dance! You have a valid
> & functioning adapter...
> ' Here you can change config,
> enable/disable, etc.
> End If
> End If
> End If
> End If
> End If
> End If
> Next ' instance of Win32_NetworkAdapterConfiguration
HTH
--Maarten


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
network adapters Drivers
Knowing when a WCF service dies... .NET General
Wireless Adapters Vista networking & sharing
Knowing version installed Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46