Powershell - PCI/PCIe slot occupation

4

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?

BowPark

Posted 2016-11-16T11:18:56.983

Reputation: 195

I don't have an answer, but take a look at https://blogs.technet.microsoft.com/wincat/2012/09/06/device-management-powershell-cmdlets-sample-an-introduction/

– Lenniey – 2016-11-16T13:06:34.040

Answers

4

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

Stu

Posted 2016-11-16T11:18:56.983

Reputation: 89

The term 'Get-device' is not recognized as the name of a cmdlet, – rogerdpack – 2018-12-27T02:21:52.173

@rogerdpack this is available from the DeviceManagement module

– Stu – 2018-12-28T23:58:50.897

0

See what buses are on a system:

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

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

There is DEVPKEY_Device_Address driver parameter, in which higher 16 bits are device number and lower 16 bits are function number:

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

...and DEVPKEY_Device_LocationInfo parameter:

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

George Sovetov

Posted 2016-11-16T11:18:56.983

Reputation: 157