I found Determining the network connection link speed and now I am trying to correlate the data from Win32_PerfRawData_Tcpip_NetworkInterface with Win32_NetworkAdapter (or Win32_NetworkAdapterConfiguration).
On the class Win32_PerfRawData_Tcpip_NetworkInterface
I don't see any
index or unique key that I can use to reference
Win32_NetworkAdapterConfiguration
or Win32_NetworkAdapter.
I tried to use the
Namein
Win32_PerfRawData_Tcpip_NetworkInterface
and
Win32_NetworkAdapter`, but still they look different.
e.g.
Name: Intel(R) PRO/1000 PL Network Connection
vs
Name: Intel[R] PRO_1000 PL Network Connection
Any hints?
Thank you in advance,
Milde
===
Maybe that piece of code will help you to help me guys :)
# I got the DeviceID of a NIC and use it to get the "NetConnection ID":
$objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or die "Exit: WMI connection failed. \n";
$colNicSetts = $objWMIService->ExecQuery(
"SELECT * FROM Win32_NetworkAdapter Where DeviceID = '$ID'", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
foreach my $objItem (in $colNicSetts){
$NetConnID = $objItem->{NetConnectionID};
}
# => $NetConnID stores "Intel(R) PRO/1000 PL Network Connection".
# Now I tried to get the Link Speed with sth. like that:
$collItems = $objWMIService->ExecQuery(
"SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface Where Name = '$NetConnID'", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
foreach my $objItem (in $collItems){
$LinkSpeed = $objItem->{CurrentBandwidth};
}
# "Win32_PerfRawData_Tcpip_NetworkInterface" contains "Intel[R] PRO_1000 PL Network" Connection
# "Intel(R) PRO/1000 PL Network Connection" != Intel[R] PRO_1000 PL Network Connection
# => $LinkSpeed empty
OK. Thanks for posting the short script. While you were working on that, I was following a different track using DBD::WMI and digging through the docs to see if you had missed anything.
I could not find a better way (there must be one) than canonicalizing the names:
Output:
I just looked to my machine withe the WMI-Tools, because I thought, it must be easy ... ;-)
but it's not ...
But what I found on my machine was, the a concatenantion of the "Win32_NetworkAdapter.Name" + " __" + "Win32_NetworkAdapter.InterfaceIndex" results in the "Win32_PerfFormattedData_Tcpip_NetworkInterface.Name="NVIDIA nForce Networking Controller _2" [Regard the space too!].
Example from my machine:
I hope, I've understood your question right and this may help?!
br--mabra
The only approach I was able to find was to use the Win32_PnPEntity class to get the DeviceName for the network adapter, then convert it into the InstanceName. This allows you to find a key value that you can use on other WMI tables (I used InterfaceIndex, but there are other choices in the Win32_NetworkAdapter class.
So at a high level:
Win32_PerfFormattedData_Tcpip_NetworkInterface
classIt is pretty convoluted, but since InstanceName is derrived from the PnPEntity Name, that is the only way I could find to get accurate mappings.
Here are the two ways I was able to get the PnPEntity instance for a NetworkAdapter: