[Windows] Replace Win32_Product call to registry query (#5887)

* Replace Win32_Product call to registry query

* Update properties
This commit is contained in:
Aleksandr Chebotov
2022-07-12 09:10:32 +02:00
committed by GitHub
parent 82c8123cac
commit 70019eaa8f

View File

@@ -277,13 +277,17 @@ function Get-GHVersion {
} }
function Get-VisualCPPComponents { function Get-VisualCPPComponents {
$vcpp = Get-CimInstance -ClassName Win32_Product -Filter "Name LIKE 'Microsoft Visual C++%'" $regKeys = @(
$vcpp | Sort-Object Name, Version | ForEach-Object { "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*"
$isMatch = $_.Name -match "^(?<Name>Microsoft Visual C\+\+ \d{4})\s+(?<Arch>\w{3})\s+(?<Ext>.+)\s+-" "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
$vcpp = Get-ItemProperty -Path $regKeys | Where-Object DisplayName -like "Microsoft Visual C++*"
$vcpp | Sort-Object DisplayName, DisplayVersion | ForEach-Object {
$isMatch = $_.DisplayName -match "^(?<Name>Microsoft Visual C\+\+ \d{4})\s+(?<Arch>\w{3})\s+(?<Ext>.+)\s+-"
if ($isMatch) { if ($isMatch) {
$name = '{0} {1}' -f $matches["Name"], $matches["Ext"] $name = '{0} {1}' -f $matches["Name"], $matches["Ext"]
$arch = $matches["Arch"].ToLower() $arch = $matches["Arch"].ToLower()
$version = $_.Version $version = $_.DisplayVersion
[PSCustomObject]@{ [PSCustomObject]@{
Name = $name Name = $name
Architecture = $arch Architecture = $arch