Board logo

标题: [转载代码] [PowerShell每日技巧]查找无线网络适配器(20140317) [打印本页]

作者: DAIC    时间: 2014-3-25 15:09     标题: [PowerShell每日技巧]查找无线网络适配器(20140317)

There are many ways of finding network adapters, but apparently none to identify active wireless adapters.

All information about your network adapters can be found right in the Registry, and here is a one-liner that provides all the information you may need:

PS C:\> Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Network\*\*\Connection' -ErrorAction SilentlyContinue | Select-Object -Property Name, DefaultNameIndex, MediaSubType
Local Area Connection* 69                                       69
Local Area Connection* 14                                       14
Wireless Network Connection                                    2 2


The interesting part is the MediaSubType value. Wireless adapters always are marked with a MediaSubType of 2.

So this line will always return wireless adapters only:

PS C:\> Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Network\*\*\Connection' -ErrorAction SilentlyContinue | Where-Object {$_.MediaSubType -eq 2} | Select-Object -Property Name, PnpInstanceID

Name                                              PnpInstanceID
----                                              -------------
Wireless Network Connection                       PCI\VEN_14E4&DEV_4353&SUBSYS_00E9106...


http://powershell.com/cs/blogs/tips/archive/2014/03/17/finding-wireless-network-adapters.aspx




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2