Powershell - PCI/PCIe 插槽占用

Powershell - PCI/PCIe 插槽占用

假设以管理员身份运行带有 Windows Powershell 5.0 的 Windows 10 系统,我需要列出所有主板插槽以及占用它们的设备的名称(如果有)。

Win32_SystemSlot, 和

Get-WmiObject -class "Win32_SystemSlot"

似乎用奇怪的数字枚举了插槽,但没有枚举设备。

Win32_PnP实体枚举的是设备,而不是插槽。

我想获得类似的东西

Slot            Device
---
PCIEX16_1       NVidia GeForce GTX 680...
PCIEX1_1        Empty

有可能吗?如果可以,怎么做?

答案1

我碰巧知道您可以使用以下方法获取网卡:

> Get-NetAdapterHardwareInfo

Name                           Segment Bus Device Function Slot NumaNode PcieLinkSpeed PcieLinkWidth Version
----                           ------- --- ------ -------- ---- -------- ------------- ------------- -------
Wi-Fi                                0   2      0        0    4               2.5 GT/s             1 1.1
Ethernet                             0   3      0        0    5               2.5 GT/s             1 1.1

使用上面@Lenniey 建议的模块,你似乎可以通过查找以“PCI 总线”开头的 LocationInfo 和非零 UINumber 来找到设备的位置:

> Get-device | where {$_.LocationInfo -like 'PCI bus*' -and $_.UINumber -ne 0} | select Name, LocationInfo, UINumber

Name                                  LocationInfo                     UINumber
----                                  ------------                     --------
Realtek PCIe GBE Family Controller    PCI bus 3, device 0, function 0         5
Intel(R) Centrino(R) Wireless-N 2230  PCI bus 2, device 0, function 0         4

在上图中,我的网卡在插槽 5 中,而我的 wifi 在插槽 4 中。

然后,您可以将其与 PCI Express 根端口列表进行比较:

> Get-device | where {$_.Name -eq 'PCI Express Root Port'} | select Name,LocationInfo

Name                   LocationInfo
----                   ------------
PCI Express Root Port  PCI bus 0, device 28, function 5
PCI Express Root Port  PCI bus 0, device 28, function 0
PCI Express Root Port  PCI bus 0, device 28, function 4

这将告诉您我有第三个插槽,但未插入任何内容,这与我在设备管理器中看到的一致。

警告:我不是硬件专家,我只是根据我在我的机器上看到的内容来猜测这一点。

为了确认这不仅与网络适配器有关,如果我删除“UINumber -ne 0”上的过滤器,我可以看到连接到 PCI 总线的所有其他设备,但是,由于它们都是内置的,所以它们没有插槽号:

Name                                                                              LocationInfo                      UINumber
----                                                                              ------------                      --------
Realtek PCIe GBE Family Controller                                                PCI bus 3, device 0, function 0          5
Intel(R) 6 Series/C200 Series Chipset Family USB Enhanced Host Controller - 1C26  PCI bus 0, device 29, function 0         0
PCI Express Root Port                                                             PCI bus 0, device 28, function 5         0
High Definition Audio Controller                                                  PCI bus 0, device 27, function 0         0
Intel(R) Centrino(R) Wireless-N 2230                                              PCI bus 2, device 0, function 0          4
Intel(R) Management Engine Interface                                              PCI bus 0, device 22, function 0         0
LPC Controller                                                                    PCI bus 0, device 31, function 0         0
PCI Express Root Port                                                             PCI bus 0, device 28, function 0         0
Memory Controller                                                                 PCI bus 0, device 0, function 0          0
PCI Express Root Port                                                             PCI bus 0, device 28, function 4         0
SM Bus Controller                                                                 PCI bus 0, device 31, function 3         0
Standard SATA AHCI Controller                                                     PCI bus 0, device 31, function 2         0
Intel(R) HD Graphics                                                              PCI bus 0, device 2, function 0          0
Thermal Control Device                                                            PCI bus 0, device 31, function 6         0
Intel(R) 6 Series/C200 Series Chipset Family USB Enhanced Host Controller - 1C2D  PCI bus 0, device 26, function 0         0

答案2

查看系统上有哪些总线:

PS C:\Users\Administrator> gwmi Win32_Bus | ft DeviceID

DeviceID
--------
PNP_BUS_0
ACPIBus_BUS_0
PCI_BUS_0

DEVPKEY_Device_Address驱动参数,高16位为设备号,低16位为功能号:

PS C:\Users\Administrator> (gwmi Win32_Bus -Filter 'DeviceID like "PCI%"').GetRelated('Win32_PnPEntity').GetDeviceProperties('DEVPKEY_Device_Address').deviceProperties | ft DeviceID,keyName,{$_.data -shr 16},{$_.data -band 0xFFFF}

DeviceID                                                     keyName                $_.data -shr 16 $_.data -band 0xFFFF
--------                                                     -------                --------------- --------------------
PCI\VEN_8086&DEV_7000&SUBSYS_00000000&REV_00\3&267A616A&0&08 DEVPKEY_Device_Address               1                    0
PCI\VEN_80EE&DEV_CAFE&SUBSYS_00000000&REV_00\3&267A616A&0&20 DEVPKEY_Device_Address               4                    0
PCI\VEN_8086&DEV_2829&SUBSYS_00000000&REV_02\3&267A616A&0&68 DEVPKEY_Device_Address              13                    0
PCI\VEN_8086&DEV_1237&SUBSYS_00000000&REV_02\3&267A616A&0&00 DEVPKEY_Device_Address               0                    0
PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&18 DEVPKEY_Device_Address               3                    0
PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&40 DEVPKEY_Device_Address               8                    0
PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&48 DEVPKEY_Device_Address               9                    0
PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&50 DEVPKEY_Device_Address              10                    0
PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&80 DEVPKEY_Device_Address              16                    0
PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&88 DEVPKEY_Device_Address              17                    0
PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&90 DEVPKEY_Device_Address              18                    0
PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&98 DEVPKEY_Device_Address              19                    0
PCI\VEN_80EE&DEV_BEEF&SUBSYS_00000000&REV_00\3&267A616A&0&10 DEVPKEY_Device_Address               2                    0

...和DEVPKEY_Device_LocationInfo范围:

PS C:\Users\Administrator> (gwmi Win32_Bus -Filter 'DeviceID like "PCI%"').GetRelated('Win32_PnPEntity').GetDeviceProperties('DEVPKEY_Device_LocationInfo').deviceProperties | ft data,DeviceID

data                             DeviceID
----                             --------
PCI bus 0, device 1, function 0  PCI\VEN_8086&DEV_7000&SUBSYS_00000000&REV_00\3&267A616A&0&08
PCI bus 0, device 4, function 0  PCI\VEN_80EE&DEV_CAFE&SUBSYS_00000000&REV_00\3&267A616A&0&20
PCI bus 0, device 13, function 0 PCI\VEN_8086&DEV_2829&SUBSYS_00000000&REV_02\3&267A616A&0&68
PCI bus 0, device 0, function 0  PCI\VEN_8086&DEV_1237&SUBSYS_00000000&REV_02\3&267A616A&0&00
PCI bus 0, device 3, function 0  PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&18
PCI bus 0, device 8, function 0  PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&40
PCI bus 0, device 9, function 0  PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&48
PCI bus 0, device 10, function 0 PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&50
PCI bus 0, device 16, function 0 PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&80
PCI bus 0, device 17, function 0 PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&88
PCI bus 0, device 18, function 0 PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&90
PCI bus 0, device 19, function 0 PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00\3&267A616A&0&98
PCI bus 0, device 2, function 0  PCI\VEN_80EE&DEV_BEEF&SUBSYS_00000000&REV_00\3&267A616A&0&10

相关内容