Can WMI query a class property and filter using another class property?

1.8k Views Asked by At

I am a WMI noob. I'm using BGInfo and have a device with 2 NICs. I'm trying to query the IP address of one of the NICs. I want to submit a query based on the name of the NIC.

However, I'm running into an issue where the IP address is stored in Win32_NetworkAdapterConfiguration and the NIC name is stored in Win32_NetworkAdapter.

I want to build a WMI query like the following:

SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE Win32_NetworkAdapter.Name="My NIC Name".

Is this possible?

1

There are 1 best solutions below

0
On BEST ANSWER

For basic understanding, run (from an open cmd window) the following command lines

wmic path Win32_NetworkAdapter get DeviceID, Index, InterfaceIndex, Name, NetConnectionId
wmic path Win32_NetworkAdapterConfiguration get Index, InterfaceIndex, IPAddress
wmic path Win32_NetworkAdapterSetting

and read the following documentation:

Then you can understand how works the following code snippet (if you use a real value for _adapterName instead of the My NIC Name placeholder):

set "_adapterName=My NIC Name"
wmic path Win32_NetworkAdapter where "Name='%_adapterName%'" ASSOC:value /RESULTCLASS:Win32_NetworkAdapterConfiguration 

Finally, you can restrict above output to the IPAddress=… line as follows:

wmic path Win32_NetworkAdapter where "Name='%_adapterName%'" ASSOC:value /RESULTCLASS:Win32_NetworkAdapterConfiguration | findstr "^IPAddress"