'Powershell. Why where {} directive can not find two matching DeviceID? One taken from Win32_VideoController, another from Regedit value
Here is code
# | Get DeviceID and Name of GPUs presented in system
$GPU_Inf = Get-CIMInstance -Query "SELECT Caption, PNPDeviceID from Win32_VideoController"
# | Obtain info on GPUs DeviceID and MemorySize from Regedit
$mem_devid_value = get-itempropertyvalue -path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4D36E968-E325-11CE-BFC1-08002BE10318}\????" -Name MatchingDeviceId, HardwareInformation.qwMemorySize
# | For Each element in GPU_Inf
foreach ($i in $GPU_Inf) {
Write-Host "Current PNPDeviceID from GPU_Inf is" $i.PNPDeviceID
Write-Host "Array of MatchingDeviceID and Memory Size from Regedit is" $mem_devid_value
Write-Host "Our MatchingDeviceID from Regedit is" $mem_devid_value[6]
}
$current_dev_id = $mem_devid_value | where { $_ -like $GPU_Inf."PNPDeviceID"}
Write-Host "Device ID that match is" $current_dev_id
And the output shows that where {} directive somehow fail to find matching DeviceIDs
Current PNPDeviceID from GPU_Inf is PCI\VEN_10DE&DEV_128B&SUBSYS_128B10DE&REV_A1\4&1A8B4BFC&0&0008
Array of MatchingDeviceID and Memory Size from Regedit is pci\ven_10de&dev_1c03 6442450944 pci\ven_10de&dev_1402 2147483648 pci\ven_10de&dev_0641 536870912 pci\ven_10de&dev_128b 2147483648
Our MatchingDeviceID from Regedit is pci\ven_10de&dev_128b
Device ID that match is
Last line is blank while it must contain mathing DeviceID from where {} directive
May be there is some wrong type of element massive or smth like this?
Solution 1:[1]
I managed to figure out how to make it work
# | Get DeviceID and Name of GPUs presenterd in system
$GPU_Inf = Get-CIMInstance -Query "SELECT Caption, PNPDeviceID from Win32_VideoController"
# | Write to collection DeviceID and HardwareInformation.qwMemorySize from all registry branches
$x = get-itemproperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Class\{4D36E968-E325-11CE-BFC1-08002BE10318}\????" -Name MatchingDeviceId, HardwareInformation.qwMemorySize | where { $GPU_Inf.PNPDeviceID -like "$($_.MatchingDeviceID)*" }
# | See that it works
$x.MatchingDeviceID
$x.'HardwareInformation.qwMemorySize'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | alive-one |