• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1328
  • Last Modified:

Grab Network info from two different namespaces

I'd like to grab the info from Win32_NetworkAdapterConfiguration Where IPEnabled = True
and use the Description of each result to then query the root\WMI namespace and the NDIS class for those same adapters...
So NetworkAdapterConfiguration returns two IP enabled nics:
Description: VMware Accelerated AMD PCNet Adapter - Packet Scheduler Miniport
Description: TAP-Win32 Adapter V9 - Packet Scheduler Miniport
And I'd like to query MSNdis_LinkSpeed where InstanceName = %the_results_from_above%
if that can be done. And if the names for some reason don't match description != instancename then print the speed is "unknown".
Below is the code I'd like to "merge" into one sub if possible, or a function, I don't know which way is best. Let me know if you have any questions!
-rich
Wscript.Echo "<Network>"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
		Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration " & "Where IPEnabled = True")
		For Each objItem in colItems
  	Wscript.Echo "<NIC>"
  	' Beginning of Adapter specific information
  	Wscript.Echo "<Caption>" & objItem.Caption & "</Caption>"
  	If Not IsNull(objItem.DNSDomainSuffixSearchOrder) Then
  	  Dim strDefaultIPGateway : strDefaultIPGateway = Join(objItem.DefaultIPGateway, ",")
  	  Wscript.Echo "<DefaultIPGateway>" & strDefaultIPGateway & "</DefaultIPGateway>"
  	End If
  	Wscript.Echo "<Description>" & objItem.Description & "</Description>"
  	If Not IsNull(objItem.DNSDomainSuffixSearchOrder) Then
  	  Dim strDNSDomainSuffixSearchOrder : strDNSDomainSuffixSearchOrder = Join(objItem.DNSDomainSuffixSearchOrder, ",")
  	  Wscript.Echo "<DNSSrchOrd>" & strDNSDomainSuffixSearchOrder & "</DNSSrchOrd>"
  	End If
  	Wscript.Echo "<DHCPEnabled>" & objItem.DHCPEnabled & "</DHCPEnabled>"
  	Wscript.Echo "<MACAddress>" & objItem.MACAddress & "</MACAddress>"
  	Wscript.Echo "<WINSPrimaryServer>" & objItem.WINSPrimaryServer & "</WINSPrimaryServer>"
  	Wscript.Echo "<WINSSecondaryServer>" & objItem.WINSSecondaryServer & "</WINSSecondaryServer>"
  	' Beginning IP Address Listing
  	Wscript.Echo "<IPAddresses>"
  	Dim i
  	For i = 0 To UBound (objItem.IPAddress)
  	  Wscript.Echo "<IPAddress>" & objItem.IPAddress(i) & "</IPAddress>"
  	  Wscript.Echo "<IPSubnet>" & objItem.IPSubnet(i) & "</IPSubnet>"
  	Next
  	' Writing End of IP Address Listing
  	Wscript.Echo "</IPAddresses>"
  	' Writing End of NIC
  	Wscript.Echo "</NIC>"
 
And....
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
   	Set colItems = objWMIService.ExecQuery("SELECT * FROM MSNdis_LinkSpeed",,48)
   		For Each objItem In colItems
   		   WScript.Echo "Active: " & objItem.Active
   		   WScript.Echo "InstanceName: " & objItem.InstanceName
   		   WScript.Echo "NdisLinkSpeed: " & objItem.NdisLinkSpeed
   		   WScript.Echo
   		Next

Open in new window

0
Rich Rumble
Asked:
Rich Rumble
  • 4
  • 3
1 Solution
 
jwarnkenCommented:

strComputer = "."
WScript.Echo "<Network>"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration " & "Where IPEnabled = True")
	For Each objItem in colItems
        Wscript.Echo "<NIC>"
        ' Beginning of Adapter specific information
        Wscript.Echo "<Caption>" & objItem.Caption & "</Caption>"
        If Not IsNull(objItem.DNSDomainSuffixSearchOrder) Then
          Dim strDefaultIPGateway : strDefaultIPGateway = Join(objItem.DefaultIPGateway, ",")
          Wscript.Echo "<DefaultIPGateway>" & strDefaultIPGateway & "</DefaultIPGateway>"
        End If
        Wscript.Echo "<Description>" & objItem.Description & "</Description>"
        If Not IsNull(objItem.DNSDomainSuffixSearchOrder) Then
          Dim strDNSDomainSuffixSearchOrder : strDNSDomainSuffixSearchOrder = Join(objItem.DNSDomainSuffixSearchOrder, ",")
          Wscript.Echo "<DNSSrchOrd>" & strDNSDomainSuffixSearchOrder & "</DNSSrchOrd>"
        End If
        Wscript.Echo "<DHCPEnabled>" & objItem.DHCPEnabled & "</DHCPEnabled>"
        Wscript.Echo "<MACAddress>" & objItem.MACAddress & "</MACAddress>"
        Wscript.Echo "<WINSPrimaryServer>" & objItem.WINSPrimaryServer & "</WINSPrimaryServer>"
        Wscript.Echo "<WINSSecondaryServer>" & objItem.WINSSecondaryServer & "</WINSSecondaryServer>"
        ' Beginning IP Address Listing
        Wscript.Echo "<IPAddresses>"
        Dim i
        For i = 0 To UBound (objItem.IPAddress)
          Wscript.Echo "<IPAddress>" & objItem.IPAddress(i) & "</IPAddress>"
          Wscript.Echo "<IPSubnet>" & objItem.IPSubnet(i) & "</IPSubnet>"
        Next
        ' Writing End of IP Address Listing
        Wscript.Echo "</IPAddresses>"
        ' Beginning of LinkSpeed
        WScript.Echo "<LinkSpeed>"
        LinkSpeed(objItem.Description)
        ' Writing End of LinkSpeed
        Wscript.Echo "</LinkSpeed>"
        ' Writing End of NIC
        Wscript.Echo "</NIC>"
 	Next
 
Sub LinkSpeed(Desc)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery("SELECT * FROM MSNdis_LinkSpeed Where InstanceName = '" & Desc & "1'",,48)	
	For Each objItem In colItems
    	WScript.Echo "Active: " & objItem.Active
        WScript.Echo "InstanceName: " & objItem.InstanceName
        WScript.Echo "NdisLinkSpeed: " & objItem.NdisLinkSpeed
	Next
End Sub 

Open in new window

0
 
jwarnkenCommented:
sorry one typo to correct
strComputer = "."
WScript.Echo "<Network>"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration " & "Where IPEnabled = True")
	For Each objItem in colItems
        Wscript.Echo "<NIC>"
        ' Beginning of Adapter specific information
        Wscript.Echo "<Caption>" & objItem.Caption & "</Caption>"
        If Not IsNull(objItem.DNSDomainSuffixSearchOrder) Then
          Dim strDefaultIPGateway : strDefaultIPGateway = Join(objItem.DefaultIPGateway, ",")
          Wscript.Echo "<DefaultIPGateway>" & strDefaultIPGateway & "</DefaultIPGateway>"
        End If
        Wscript.Echo "<Description>" & objItem.Description & "</Description>"
        If Not IsNull(objItem.DNSDomainSuffixSearchOrder) Then
          Dim strDNSDomainSuffixSearchOrder : strDNSDomainSuffixSearchOrder = Join(objItem.DNSDomainSuffixSearchOrder, ",")
          Wscript.Echo "<DNSSrchOrd>" & strDNSDomainSuffixSearchOrder & "</DNSSrchOrd>"
        End If
        Wscript.Echo "<DHCPEnabled>" & objItem.DHCPEnabled & "</DHCPEnabled>"
        Wscript.Echo "<MACAddress>" & objItem.MACAddress & "</MACAddress>"
        Wscript.Echo "<WINSPrimaryServer>" & objItem.WINSPrimaryServer & "</WINSPrimaryServer>"
        Wscript.Echo "<WINSSecondaryServer>" & objItem.WINSSecondaryServer & "</WINSSecondaryServer>"
        ' Beginning IP Address Listing
        Wscript.Echo "<IPAddresses>"
        Dim i
        For i = 0 To UBound (objItem.IPAddress)
          Wscript.Echo "<IPAddress>" & objItem.IPAddress(i) & "</IPAddress>"
          Wscript.Echo "<IPSubnet>" & objItem.IPSubnet(i) & "</IPSubnet>"
        Next
        ' Writing End of IP Address Listing
        Wscript.Echo "</IPAddresses>"
        ' Beginning of LinkSpeed
        WScript.Echo "<LinkSpeed>"
        LinkSpeed(objItem.Description)
        ' Writing End of LinkSpeed
        Wscript.Echo "</LinkSpeed>"
        ' Writing End of NIC
        Wscript.Echo "</NIC>"
 	Next
 
Sub LinkSpeed(Desc)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery("SELECT * FROM MSNdis_LinkSpeed Where InstanceName = '" & Desc & "'",,48)	
	For Each objItem In colItems
    	WScript.Echo "Active: " & objItem.Active
        WScript.Echo "InstanceName: " & objItem.InstanceName
        WScript.Echo "NdisLinkSpeed: " & objItem.NdisLinkSpeed
	Next
End Sub 

Open in new window

0
 
Rich RumbleSecurity SamuraiAuthor Commented:
That worked great!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Rich RumbleSecurity SamuraiAuthor Commented:
How could I do a join so that the xml tag's appear on the same line as the output, see the code below.
-rich
strComputer = "."
WScript.Echo "<Network>"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration " & "Where IPEnabled = True")
        For Each objItem in colItems
        Wscript.Echo "<NIC>"
        ' Beginning of Adapter specific information
        Wscript.Echo "<Caption>" & objItem.Caption & "</Caption>"
        If Not IsNull(objItem.DNSDomainSuffixSearchOrder) Then
          Dim strDefaultIPGateway : strDefaultIPGateway = Join(objItem.DefaultIPGateway, ",")
          Wscript.Echo "<DefaultIPGateway>" & strDefaultIPGateway & "</DefaultIPGateway>"
        End If
        Wscript.Echo "<Description>" & objItem.Description & "</Description>"
        If Not IsNull(objItem.DNSDomainSuffixSearchOrder) Then
          Dim strDNSDomainSuffixSearchOrder : strDNSDomainSuffixSearchOrder = Join(objItem.DNSDomainSuffixSearchOrder, ",")
          Wscript.Echo "<DNSSrchOrd>" & strDNSDomainSuffixSearchOrder & "</DNSSrchOrd>"
        End If
        Wscript.Echo "<DHCPEnabled>" & objItem.DHCPEnabled & "</DHCPEnabled>"
        Wscript.Echo "<MACAddress>" & objItem.MACAddress & "</MACAddress>"
        Wscript.Echo "<WINSPrimaryServer>" & objItem.WINSPrimaryServer & "</WINSPrimaryServer>"
        Wscript.Echo "<WINSSecondaryServer>" & objItem.WINSSecondaryServer & "</WINSSecondaryServer>"
        ' Beginning IP Address Listing
        Wscript.Echo "<IPAddresses>"
        Dim i
        For i = 0 To UBound (objItem.IPAddress)
          Wscript.Echo "<IPAddress>" & objItem.IPAddress(i) & "</IPAddress>"
          Wscript.Echo "<IPSubnet>" & objItem.IPSubnet(i) & "</IPSubnet>"
        Next
        ' Writing End of IP Address Listing
        Wscript.Echo "</IPAddresses>"
        ' Beginning of LinkSpeed
        WScript.Echo "<LinkSpeed>" 
        LinkSpeed(objItem.Description)
        Wscript.Echo "</LinkSpeed>"
        ' Writing End of NIC
        Wscript.Echo "</NIC>"
        Next
 
Sub LinkSpeed(Desc)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery("SELECT * FROM MSNdis_LinkSpeed Where InstanceName = '" & Desc & "'",,48)
        For Each objItem In colItems
        WScript.Echo objItem.NdisLinkSpeed
        Next
End Sub

Open in new window

0
 
Rich RumbleSecurity SamuraiAuthor Commented:
So instead of this:
<LinkSpeed>
100000
</LinkSpeed>

have this: <LinkSpeed>100000</LinkSpeed>
Thanks again!
0
 
jwarnkenCommented:

Change the sub to WScript.Echo "<NdisLinkSpeed>" & objItem.NdisLinkSpeed & "</NdisLinkSpeed>"
 Then the result will be
<LinkSpeed>
<NdisLinkSpeed>100000</NdisLinkSpeed>
</LinkSpeed>

I just added the <LinkSpeed> Tag as a place holder to call the sub You can remove it or move it to the sub without affecting the script
0
 
Rich RumbleSecurity SamuraiAuthor Commented:
Ahh, I should of tried that, so simple :)
Thanks again!
-rich
strComputer = "."
WScript.Echo "<Network>"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration " & "Where IPEnabled = True")
        For Each objItem in colItems
        Wscript.Echo "<NIC>"
        ' Beginning of Adapter specific information
        Wscript.Echo "<Caption>" & objItem.Caption & "</Caption>"
        If Not IsNull(objItem.DNSDomainSuffixSearchOrder) Then
          Dim strDefaultIPGateway : strDefaultIPGateway = Join(objItem.DefaultIPGateway, ",")
          Wscript.Echo "<DefaultIPGateway>" & strDefaultIPGateway & "</DefaultIPGateway>"
        End If
        Wscript.Echo "<Description>" & objItem.Description & "</Description>"
        If Not IsNull(objItem.DNSDomainSuffixSearchOrder) Then
          Dim strDNSDomainSuffixSearchOrder : strDNSDomainSuffixSearchOrder = Join(objItem.DNSDomainSuffixSearchOrder, ",")
          Wscript.Echo "<DNSSrchOrd>" & strDNSDomainSuffixSearchOrder & "</DNSSrchOrd>"
        End If
        Wscript.Echo "<DHCPEnabled>" & objItem.DHCPEnabled & "</DHCPEnabled>"
        Wscript.Echo "<MACAddress>" & objItem.MACAddress & "</MACAddress>"
        Wscript.Echo "<WINSPrimaryServer>" & objItem.WINSPrimaryServer & "</WINSPrimaryServer>"
        Wscript.Echo "<WINSSecondaryServer>" & objItem.WINSSecondaryServer & "</WINSSecondaryServer>"
        ' Beginning IP Address Listing
        Wscript.Echo "<IPAddresses>"
        Dim i
        For i = 0 To UBound (objItem.IPAddress)
          Wscript.Echo "<IPAddress>" & objItem.IPAddress(i) & "</IPAddress>"
          Wscript.Echo "<IPSubnet>" & objItem.IPSubnet(i) & "</IPSubnet>"
        Next
        ' Writing End of IP Address Listing
        Wscript.Echo "</IPAddresses>"
        ' Beginning of LinkSpeed
        LinkSpeed(objItem.Description)
        ' Writing End of NIC
        Wscript.Echo "</NIC>"
        Next
 
Sub LinkSpeed(Desc)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery("SELECT * FROM MSNdis_LinkSpeed Where InstanceName = '" & Desc & "'",,48)
        For Each objItem In colItems
        WScript.Echo "<LinkSpeed>" & objItem.NdisLinkSpeed & "</LinkSpeed>" 
        Next
End Sub

Open in new window

0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now