Reputation: 4928
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?
Upvotes: 0
Views: 2194
Reputation: 30153
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:
WMI
class relates a network adapter and its configuration settings.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"
Upvotes: 2