If I run
Get-WmiObject -Class Win32_NetworkAdapter
I get a list of the Network Adapters in my system plus some information about the adapter. What I don’t get is the IP addressing and other configuration information because it is stored on the Win32_NetworkAdapterConfiguration class.
The key property on Win32_NetworkAdapter is DeviceId. My wireless card is DeviceId 11.
There is an association between the Win32_NetworkAdapter class and the corresponding Win32_NetworkAdapterConfiguration class. The Win32_NetworkAdapterConfiguration class uses Index to identify the card and
Win32_NetworkAdapter.DeviceId = Win32_NetworkAdapterConfiguration.Index
So I could do this
Get-WmiObject -Class Win32_NetworkAdapter -Filter “DeviceID=11″
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter “Index=11″
A better way is work through the association
$nic = Get-WmiObject -Class Win32_NetworkAdapter -Filter “DeviceID=11″
$nic
$q = “ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID=$($nic.DeviceID)} WHERE ResultClass = Win32_NetworkAdapterConfiguration”
Get-WmiObject -Query $q
I tend to use WQL but there is an alternative
$nic = Get-WmiObject -Class Win32_NetworkAdapter -Filter “DeviceID=11″
$nic
$nic.GetRelated(“Win32_NetworkAdapterConfiguration”)
The WMI object has a GetRelated() method
if you just do
$nic.GetRelated()
you will get all associations – its the equivalent of
$q = “ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID=$($nic.DeviceID)} “
Get-WmiObject -Query $q
One slight problem is that if you do
$nic | Get-Member
you won’t see the method – you will need to do this
$nic | Get-Member -View base
Which one should you use? Its your choice. I tend to use WQL out of habit but GetRelated() is less typing.