【问题标题】:How to get the type of an network adapter (Wi-Fi, Ethernet, Bluetooth) in Windows Powershell?如何在 Windows Powershell 中获取网络适配器(Wi-Fi、以太网、蓝牙)的类型?
【发布时间】:2022-01-04 14:02:16
【问题描述】:

如何在 Windows Powershell 中获取网络适配器的类型(Wi-Fi、以太网、蓝牙)?

目前我正在使用:get-wmiobject win32_networkadapter -filter "PhysicalAdapter = true" | select *

它提供了有关每个适配器的大量信息。属性“名称”包含一些指示它是哪种类型的设备,但是否有类似 Id 的东西告诉我类型:

这是一个适配器的示例:

PSComputerName              : XXXXXXXXXXXX
Availability                : 3
Name                        : Intel(R) Wi-Fi 6 AX201 160MHz
Status                      :
StatusInfo                  :
DeviceID                    : 2
__GENUS                     : 2
__CLASS                     : Win32_NetworkAdapter
__SUPERCLASS                : CIM_NetworkAdapter
__DYNASTY                   : CIM_ManagedSystemElement
__RELPATH                   : Win32_NetworkAdapter.DeviceID="2"
__PROPERTY_COUNT            : 40
__DERIVATION                : {CIM_NetworkAdapter, CIM_LogicalDevice, CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER                    : XXXXXXXX
__NAMESPACE                 : root\cimv2
__PATH                      : \\XXXXXXXXX\root\cimv2:Win32_NetworkAdapter.DeviceID="2"
AdapterType                 : Ethernet 802.3
AdapterTypeId               : 0
AutoSense                   :
Caption                     : [00000002] Intel(R) Wi-Fi 6 AX201 160MHz
ConfigManagerErrorCode      : 0
ConfigManagerUserConfig     : False
CreationClassName           : Win32_NetworkAdapter
Description                 : Intel(R) Wi-Fi 6 AX201 160MHz
ErrorCleared                :
ErrorDescription            :
GUID                        : {FDFFD175-8A12-4FFC-B5A7-583B96A192C0}
Index                       : 2
InstallDate                 :
Installed                   : True
InterfaceIndex              : 26
LastErrorCode               :
MACAddress                  : BC:17:B8:61:B8:9A
Manufacturer                : Intel Corporation
MaxNumberControlled         : 0
MaxSpeed                    :
NetConnectionID             : WLAN
NetConnectionStatus         : 2
NetEnabled                  : True
NetworkAddresses            :
PermanentAddress            :
PhysicalAdapter             : True
PNPDeviceID                 : PCI\VEN_8086&DEV_06F0&SUBSYS_00708086&REV_00\3&11583659&0&A3
PowerManagementCapabilities :
PowerManagementSupported    : False
ProductName                 : Intel(R) Wi-Fi 6 AX201 160MHz
ServiceName                 : Netwtw10
Speed                       : 1451650000
SystemCreationClassName     : Win32_ComputerSystem
SystemName                  : XXXXXXXXX
TimeOfLastReset             : 20220104082447.500000+060
Scope                       : System.Management.ManagementScope
Path                        : \\20IAV500030N-0\root\cimv2:Win32_NetworkAdapter.DeviceID="2"
Options                     : System.Management.ObjectGetOptions
ClassPath                   : \\XXXXXXXX\root\cimv2:Win32_NetworkAdapter
Properties                  : {AdapterType, AdapterTypeId, AutoSense, Availability...}
SystemProperties            : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
Qualifiers                  : {dynamic, Locale, provider, UUID}
Site                        :
Container                   :

【问题讨论】:

  • 你可以试试(Get-NetAdapter).PhysicalMediaType
  • 我想试试看:但是我应该把(Get-NetAdapter).PhysicalMediaType放在哪里?
  • 像执行上一个命令一样运行它并查看结果。如果它们符合您的喜好,那么我们可以将其合并到更漂亮的输出中。
  • 输出比较短,像Native 802.11 Unspecified 802.3 Unspecified BlueTooth 802.3 802.3这样的一个列表,但是如何映射到对应的适配器上呢?
  • 您可以使用Get-NetAdapter | Format-List *查看可用的属性。使用该属性视图,您可以通过管道传输到 Select-Object 并选择适当的属性 -> Get-NetAdapter | Select Name,PhysicalMediaType,MacAddress,InterfaceDescription 是一个示例。您可以使用 Calculated Properties 组合来自多个命令的输出。

标签: windows powershell networking wmi get-wmiobject


【解决方案1】:

以下 PowerShell 命令返回适配器的类型:

Get-NetAdapter  * | Format-List -Property "Name", "InterfaceDescription" ,"PhysicalMediaType"

样本输出:

Name                 : WLAN
InterfaceDescription : Intel(R) Wi-Fi 6 AX201 160MHz
PhysicalMediaType    : Native 802.11
 
Name                 : vEthernet (Default Switch)
InterfaceDescription : Hyper-V Virtual Ethernet Adapter
PhysicalMediaType    : Unspecified

Name                 : Bluetooth-Netzwerkverbindung
InterfaceDescription : Bluetooth Device (Personal Area Network)
PhysicalMediaType    : BlueTooth

Name                 : Ethernet 2
InterfaceDescription : Intel(R) Ethernet Connection (10) I219-LM
PhysicalMediaType    : 802.3

物理媒体类型

  • 802.3 -> 以太网
  • BlueTooth -> 猜猜看
  • Native 802.11 -> 无线局域网

感谢@AdminOfThings 的支持!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    相关资源
    最近更新 更多