hrhr123
hrhr123

Reputation: 1

Are there any way to find the Product ID ( Product code ) for each of msi file?

Member.

I've struggled to find the Produt ID by using PowerShell. I've found below but , I can't understand what each of line means.

is there any more simple way to find the Product ID by using powerhsell and cmd or could you explain each of line ?

The ps1 that I’m referring is Get-GuidFromMsiFile.ps1. In order to delivery the Msi file for client from MDM server , It uses each Product ID ( Product Code ) we use for each of msi file.

As far as I looked into , there are not easy way and found below site. But I couldn’t understand each of line meaning.

It would be really nice if someone could explain why each of line needed ( it would be nice if you could tell me any alternate way to find the product id ( product code ) for each of msi file.

https://adamrushuk.github.io/get-product-id-guid-directly-from-msi-file/

—- The background the reason why I asked here is… —- I’m thinking to use the CSP below , its CSP needs the product ID to delivery the msi file But I dont know how to find the msi’ s product ID https://learn.microsoft.com/en-us/windows/client-management/mdm/enterprisedesktopappmanagement-csp

Upvotes: 0

Views: 1591

Answers (1)

Nick Schroeder
Nick Schroeder

Reputation: 1462

I downloaded Powershell 7 MSI and then created this script.ps1 on the desktop.

param(
    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()] [System.IO.FileInfo]$Path,
    [parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()] [ValidateSet("ProductCode", "ProductVersion", "ProductName", "Manufacturer", "ProductLanguage", "FullVersion")] [string]$Property )
Process {
    try {
        $WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
        $MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @($Path.FullName, 0))
        $Query = "SELECT Value FROM Property WHERE Property = '$($Property)'"
        $View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query))
        $View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)
        $Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null)
        $Value = $Record.GetType().InvokeMember("StringData", "GetProperty", $null, $Record, 1)
        $MSIDatabase.GetType().InvokeMember("Commit", "InvokeMethod", $null, $MSIDatabase, $null);
        $View.GetType().InvokeMember("Close", "InvokeMethod", $null, $View, $null);
        $MSIDatabase = $null;
        $View = $null;
        return $Value;
    }
    catch { Write-Warning -Message $_.Exception.Message ; break } 
} End { 
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($WindowsInstaller) | Out-Null [System.GC]::Collect
}

I ran the script against the MSI and got the expected results.

PS C:\Users\azureuser> .\Desktop\script.ps1 -Path "C:\Users\azureuser\Downloads\PowerShell-7.1.3-win-x64.msi" -Property ProductCode
{A6307460-5CB8-47E2-91FE-A35552EA2C39}

PS C:\Users\azureuser> .\Desktop\script.ps1 -Path "C:\Users\azureuser\Downloads\PowerShell-7.1.3-win-x64.msi" -Property ProductName
PowerShell 7-x64

Upvotes: 1

Related Questions