Powershell - PCI/PCIe slot occupation

Given a Windows 10 system with Windows Powershell 5.0 ran as Administrator, I need to list all the motherboard slots and the name of the devices that occupy them, if any.

Win32_SystemSlot, with

Get-WmiObject -class "Win32_SystemSlot"

seems to enumerate the slots with weird numbers, but not the devices.

Win32_PnPEntity enumerates instead the devices, without the slots.

I would like to obtain something like

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

Is it possible? If yes, how?


I happen to know you get get this for network cards using:

> 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

Using the module suggested by @Lenniey above you It looks like you can find the location of devices by looking for those with a LocationInfo starting "PCI bus", and a non-zero 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

In the above, I've got my network card in slot 5, and my wifi in slot 4.

You can then compare this with the list of PCI Express Root Ports:

> 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

That will tell you that I have a third slot with nothing plugged in, which agrees with what I see in Device Manager.

Caveat; I'm not a hardware expert, I just guessed this based on what I can see on my machine.

To confirm this isn't just related to network adapters, if I remove the filter on 'UINumber -ne 0', I can see all other devices connected to the PCI bus, however, since they are all built in, they don't have a slot number:

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