How to get the IP Address for your Local Area Connection on Windows Server?
Here's some sample code I used in a previous script...
Dim myIPAddress : myIPAddress = ""
Dim objWMIService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Dim colAdapters : Set colAdapters = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
Dim objAdapter
For Each objAdapter in colAdapters
If Not IsNull(objAdapter.IPAddress) Then myIPAddress = trim(objAdapter.IPAddress(0))
exit for
Next
Wscript.echo "My IPAddress is " & myIPAddress
If you want to return the IP address into a variable, you could do the following:
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='TRUE'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
strIPAddress = Join(objItem.IPAddress, ",")
*yourFunctionName*(strIPAddress)
Next
This code is taken straight from the Scriptomatic v2.0 from Microsoft's TechNet Scriptcenter. Found here: http://technet.microsoft.com/en-us/scriptcenter/dd939957.aspx