Antony Thomas
Antony Thomas

Reputation: 3696

Powershell get-netadapter differs frrom get-wmiobject win32_networkadapter

I am trying to query for physical network adapters and I see different result from different approaches

get-wmiobject win32_networkadapter  -Filter "NetEnabled='True' and  PhysicalAdapter='True'"| select netconnectionid, name, netconnecionstatus

returns

get-wmiobject win32_networkadapter

whereas

get-netadapter -physical

returns only

enter image description here

I was under the assumption that -physical is same as PhysicalAdapter='True' but that don't seem to be the case as seen from the results. why?

Upvotes: 0

Views: 3480

Answers (2)

MisterSeajay
MisterSeajay

Reputation: 4689

The cmdlets return different data types:

[PS]> (Get-NetAdapter -Physical).GetType().FullName
Microsoft.Management.Infrastructure.CimInstance

[PS]> (Get-WmiObject -Class "Win32_NetworkAdapter").GetType().FullName
System.Object[]

[PS]> (Get-WmiObject -Class "Win32_NetworkAdapter")[0].GetType().FullName
System.Management.ManagementObject

I'm not sure I can do the CimInstance-vs-WMI discussion any justice here, so you might want to start with reading these blogs:

The cmdlets might be doing different things under the hood, but this doesn't necessarily explain why you see more interfaces using one method. It might simply be that some of the interfaces returned by Get-WMIObject are "hidden" interfaces. Note that Get-NetAdapter supports the -IncludeHidden switch.

Get-NetAdapter

The Get-NetAdapter cmdlet gets the basic network adapter properties. By default only visible adapters are returned.

Upvotes: 1

Nigel Tatschner
Nigel Tatschner

Reputation: 23

As I don't have Windows 8/2012 installed I can't verify the exact xml used for Get-NetAdapter I can't post it here but what is it probably doing is following a default formatting template for that cmdlet.

It's basically a XML file that decides what properties to display and how to format them.

The WMI object dose not have any as its not a product of a direct cmdlet, its just pulling informations from the wmi class.

Upvotes: 0

Related Questions