使用PowerShell查询USB音频设备时Parent属性为空,设备管理器中却不为空
WMI查询USB音频设备Parent属性为空的原因及解决方法
原因
你通过Win32_USBControllerDevice获取的Win32_USBDevice对象,其Parent属性在WMI实现中未填充有效数据。设备管理器显示的父设备信息来自Windows设备树的层级关联,WMI并未将该关联直接映射到Win32_USBDevice的Parent字段。
解决方法
要获取正确的父设备信息,需通过Win32_DeviceParent关联类查询设备间的父子关系。修改后的PowerShell命令如下:
# 筛选USB音频设备 $usbAudio = gwmi Win32_USBControllerDevice | ForEach-Object {[wmi]$_.Dependent} | Where-Object {$_.Service -match 'usbaudio'} # 关联父设备并输出结果 $usbAudio | ForEach-Object { $parentPath = (gwmi Win32_DeviceParent | Where-Object {$_.Dependent -eq $_.__PATH}).Antecedent [PSCustomObject]@{ Manufacturer = $_.Manufacturer Name = $_.Name Parent = ([wmi]$parentPath).Name } } | Sort-Object Manufacturer, Name, Parent | Format-Table -GroupBy Manufacturer Name, Parent
该命令通过设备的WMI路径(__PATH)匹配Win32_DeviceParent中的关联关系,提取父设备的名称,最终输出和设备管理器一致的父设备信息。
内容的提问来源于stack exchange,提问作者DoomneT
相关产品推荐
相关产品推荐

