简体   繁体   中英

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

在此处输入图片说明

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM