Ying Li at myITforum.com

PowerShell & System Center

VB/WMI script to get IP information (Window 2000/NT)

Here is a VB script to use the Win32_NetworkAdapter class and the DeviceID property (as the netConnectionID property is not available in Windows 2000/NT)to determine the MAC address of the active network connection. Then use the Win32_NetworkAdapterconfiguration class to find the IP address associated with the MAC address.

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

‘you could change the number here
Set colNics = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapter " _
        & "Where DeviceID = " & _
        "'7'")
 
For Each objNic in colNics
    strMACAddress = objNic.MACAddress
Next

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration")

For Each objItem in colItems

    If objItem.MACAddress = strMACAddress Then

 For Each strDefaultIPGateway in objItem.DefaultIPGateway
 Wscript.Echo "DefaultIPGateway: " & strDefaultIPGateway
        Next

    End If
Next

Posted: Mar 07 2007, 12:51 PM by yli628 | with no comments
Filed under:

Comments

No Comments