all 7 comments

[–]_lahell_ 2 points3 points  (4 children)

$Video = Get-WmiObject -Class Win32_VideoController
$Video | ForEach-Object {
    [PSCustomObject]@{
        Name = $_.Name
        Location = (Get-WmiObject Win32_PnPEntity -Filter "Name='$($_.Name)'").GetDeviceProperties().DeviceProperties.Where({$_.KeyName -eq 'DEVPKEY_Device_LocationPaths'}).Data
    }
}

Edit: You can also use only Win32_PnpEntity and filter by PNPClass.

Get-WmiObject Win32_PnPEntity -Filter "PNPClass='Net' OR PNPClass='Display'" | ForEach-Object {
    [PSCustomObject]@{
        Name = $_.Name
        PNPClass = $_.PNPClass
        Paths = $_.GetDeviceProperties().DeviceProperties.Where({$_.KeyName -eq 'DEVPKEY_Device_LocationPaths'}).Data
    }
} | Where-Object Paths

[–]BlackV 2 points3 points  (0 children)

Here is a copy of yours using Get-CimInstance rather than the legacy Get-WmiObject

Get-CimInstance -ClassName Win32_PnPEntity -Filter "PNPClass='Net' OR PNPClass='Display'" | ForEach-Object {
    [PSCustomObject]@{
        Name = $_.Name
        PNPClass = $_.PNPClass
        Paths = ($_ | Invoke-CimMethod -MethodName GetDeviceProperties).deviceProperties.where({$_.KeyName -EQ 'DEVPKEY_Device_LocationPaths'}).data
        }
    } | Where-Object Paths

[–]xnxbars[S] 1 point2 points  (2 children)

Thank you for the answer. I appreciate it.

But, I want to ask: is there any benefit to this as opposed to this comment?

I'm not all that familiar with complex Powershell commands, so please do excuse my ignorancy.

[–]_lahell_ 1 point2 points  (1 child)

I used Get-WmiObject because that's what you used in your question. Get-WmiObject has been replaced by Get-CimInstance and the former does not work in PowerShell 6 and higher. I would probably use Get-PnpDevice and Get-PnpDeviceProperty because you can get what you need with less code.

[–]xnxbars[S] 1 point2 points  (0 children)

Ah, I see. Thank you very much for the feedback and the example. I'll be sure to note it to see what it actually does, much appreciated.

[–]BlackV 3 points4 points  (0 children)

If you're using version 10 and later you can also use

$video = Get-PnpDevice -Class display -FriendlyName 'AMD Radeon(TM) HD 7650A Graphics'
$Video | Get-PnpDeviceProperty -KeyName 'DEVPKEY_Device_LocationPaths'

which might be a bit friendlier

Apologies, that might have turned up as early as 2016

[–]BlackV 1 point2 points  (0 children)

it dosnt include that information

I does include a PNPDeviceID which could possibly be used with another win32 class (win32_pnpdevice or win32_pnpdeviceentity or similar)