Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"Win32_NetworkAdapter" -namespace "root\CIMV2" -Filter AdapterTypeId=0

275 views
Skip to first unread message

Old Dog

unread,
Mar 20, 2008, 3:33:58 PM3/20/08
to
Hi,

I was wondering where I can find a list ot those things I can filter
on in this class. -Filter AdapterTypeId=0 helps some, but it still
list a bunch of Virtual Adaptors that I am not interested in at this
time. What I want is just the Hardware Nics, with the IP enabled.

$colItems = get-wmiobject -class "Win32_NetworkAdapter" -namespace
"root\CIMV2" -Filter AdapterTypeId=0 '
-computername $strComputer
foreach ($objItem in $colItems) {
$z.Cells.Item($row, 7) = $objItem.Caption
}

urkec

unread,
Mar 20, 2008, 4:20:01 PM3/20/08
to
"Old Dog" wrote:


Win32_NetworkAdapterConfiguration has IPEnabled property. Maybe you can
select instances where IPEnabled is True and associate them with
Win32_NetworkAdapter instances using Win32_NetworkAdapterSetting class.

Hal Rottenberg

unread,
Mar 21, 2008, 8:42:34 AM3/21/08
to
Old Dog wrote:
> I was wondering where I can find a list ot those things I can filter
> on in this class. -Filter AdapterTypeId=0 helps some, but it still
> list a bunch of Virtual Adaptors that I am not interested in at this
> time. What I want is just the Hardware Nics, with the IP enabled.

Got a bunch of tips for you:

1. MSDN is your friend. Google on the class names e.g. win32_networkadapter
2. There's some nice GUI tools, not the least of which is Mow's WMI Explorer
which is actually written in powershell [1].
3. Most importantly, learn the Get-Member cmdlet [2]. This will let you examine
the objects returned by WMI. A lot (but not all) of the properties on the WMI
objects are pretty self-explanatory.

> $colItems = get-wmiobject -class "Win32_NetworkAdapter" -namespace
> "root\CIMV2" -Filter AdapterTypeId=0 '
> -computername $strComputer
> foreach ($objItem in $colItems) {
> $z.Cells.Item($row, 7) = $objItem.Caption
> }

4. Let me guess--you know Vbscript pretty well. :) Let me suggest that you NOT
write a script until you've done #3 above and already "know the answer". If you
don't use powershell interactively at the command-line you are missing half the fun.

So, forget all of the above and start like so:

PS > get-wmiobject -list | select-string network

Or with aliases and shortened parameters (which you should learn):

PS > gwmi -li | ss network

I'll go ahead and tell you that one of the most interesting of these to look at
for your purposes will be win32_networkadapterconfiguration.

PS > gwmi win32_networkadapterconfiguration | gm

(GM is Get-Member.) There's a ton of stuff here. Try filtering down a little:

PS > gwmi win32_networkadapterconfiguration | gm *ip*

You probably see some interesting things in here. Now try pulling some out
using the Format-Table cmdlet (alias ft):

gwmi Win32_NetworkAdapterConfiguration | ft caption,ipaddress,defaultipgateway

Note that only a few have IP addresses defined. Also note that the IP address
and gateway are in curly braces. That is powershell indicating to you that the
contents of that property are an array. As you probably know, you can bind
multiple IP addresses to a NIC.

Instead of running the WMI query over and over again, first assign it to a variable.

$NetConf = gwmi win32_networkadapterconfiguration

So now try using the Where-Object cmdlet (alias ?), which for most people will
be easier than learning WQL if they are not already familiar with that syntax.
The argument to Where-Object is a statement in curly braces. If that script
block evaluates to true, the current object in the pipeline goes to the next
step. $_ is an automatic variable that indicates the current pipeline object.

$NetConf | ? { $_.IPAddress } | ft Caption,IPAddress,DefaultIPGateway

That should be pretty darn close to the result you want. There's an IPEnabled
property which you could check, but it turns out most of the virtual NICs use IP
so it's not that useful. You could go further with stuff like this:

$NetConf | ? { $_.IPAddress -and $_.IPAddress -notcontains "0.0.0.0" }

Or, this one works because most of the time you won't have multiple NICs with a
default gateway:

$NetConf | ? { $_.DefaultIPGateway }

Or maybe your hardware is predictable and you want to pull out NICs using a
certain driver.

$NetConf | ? { $_.ServiceName -eq "BCM43XX" }

Or,

$NetConf | ? { $_.Description -match "Wireless" }


[1]: http://thepowershellguy.com/blogs/posh/archive/tags/WMI+Explorer/default.aspx
[2]:
http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/get-member.mspx

--

Hal Rottenberg
Blog: http://halr9000.com
Webmaster, Psi (http://psi-im.org)
Co-host, PowerScripting Podcast (http://powerscripting.net)

Shay Levi

unread,
Mar 21, 2008, 5:49:06 PM3/21/08
to

> gwmi -li | ss network

There is no ss alias by default, though IMO it should have been :)

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

PS>>

> Or with aliases and shortened parameters (which you should learn):
>
PS>> gwmi -li | ss network

PS>>

> I'll go ahead and tell you that one of the most interesting of these
> to look at for your purposes will be
> win32_networkadapterconfiguration.
>
PS>> gwmi win32_networkadapterconfiguration | gm

PS>>

> (GM is Get-Member.) There's a ton of stuff here. Try filtering down
> a little:
>
PS>> gwmi win32_networkadapterconfiguration | gm *ip*

PS>>

0 new messages