Created
October 27, 2020 07:52
-
-
Save ZhaoTzuHsien/373635e7c40b75b578885159b1e3f822 to your computer and use it in GitHub Desktop.
Get Product Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wmipackages = Get-WmiObject -Class win32_product | |
$wmiproperties = gwmi -Query "SELECT ProductCode,Value FROM Win32_Property WHERE Property='UpgradeCode'" | |
$packageinfo = New-Object System.Data.Datatable | |
[void]$packageinfo.Columns.Add("Name") | |
[void]$packageinfo.Columns.Add("ProductCode") | |
[void]$packageinfo.Columns.Add("UpgradeCode") | |
foreach ($package in $wmipackages) | |
{ | |
$foundupgradecode = $false # Assume no upgrade code is found | |
foreach ($property in $wmiproperties) { | |
if ($package.IdentifyingNumber -eq $property.ProductCode) { | |
[void]$packageinfo.Rows.Add($package.Name,$package.IdentifyingNumber, $property.Value) | |
$foundupgradecode = $true | |
break | |
} | |
} | |
if(-Not ($foundupgradecode)) { | |
# No upgrade code found, add product code to list | |
[void]$packageinfo.Rows.Add($package.Name,$package.IdentifyingNumber, "") | |
} | |
} | |
$packageinfo | Format-table ProductCode, UpgradeCode, Name | |
# Enable the following line to export to CSV (good for annotation). Set full path in quotes | |
# $packageinfo | Export-Csv "[YourFullWriteablePath]\MsiInfo.csv" | |
# copy this line as well |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment