How to Convert a Product Code to a GUID

Adam Bertram

Adam Bertram

Read more posts by this author.

As a SCCM admin I sometimes have to reverse engineer packages. In this instance, I had a line of business application that whoever packaged it up was on drugs. To remove this application without any remnants I was forced to analyze the uninstall procedure. During this process I had a need to convert a product code (compressed GUID) to a normal GUID to find instances in the registry. To do this, you’re forced to adhere to some strange methodology.

At one time I found an obscure Vbscript to do this that was nearly 20 lines long. I have saved you from this trouble and have created this handy PowerShell function to do the dirty work for you.

function Convert-CompressedGuidToGuid {
            This converts a compressed GUID also known as a product code into a GUID.
            This function will typically be used to figure out the MSI installer GUID that matches up with the product code stored in the 'SOFTWARE\Classes\Installer\Products'	registry path.
            Convert-CompressedGuidToGuid -CompressedGuid '2820F6C7DCD308A459CABB92E828C144'
            This example would output the GUID '{7C6F0282-3DCD-4A80-95AC-BB298E821C44}'
        .PARAMETER CompressedGuid
            The compressed GUID you'd like to convert.
    param (
        [Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, Mandatory)]
    process {
        $Indexes = [ordered]@{
            0 = 8;
            8 = 4;
            12 = 4;
            16 = 2;
            18 = 2;
            20 = 2;
            22 = 2;
            24 = 2;
            26 = 2;
            28 = 2;
            30 = 2
        $Guid = '{'
        foreach ($index in $Indexes.GetEnumerator()) {
            $part = $CompressedGuid.Substring($index.Key, $index.Value).ToCharArray()
            $Guid += $part -join ''
        $Guid = $Guid.Insert(9,'-').Insert(14, '-').Insert(19, '-').Insert(24, '-')
        $Guid + '}'

Subscribe to Adam the Automator

Get the latest posts delivered right to your inbox

Looks like you're offline!