Quantcast
Channel: ConfigMgr – Adam, the Automator
Viewing all articles
Browse latest Browse all 19

Convert a Product Code to a GUID

$
0
0

As a ConfigMgr 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 {
	<#
	.SYNOPSIS
		This converts a compressed GUID also known as a product code into a GUID.	
	.DESCRIPTION
		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.
	.EXAMPLE
		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.
	#>
	[CmdletBinding()]
	[OutputType([System.String])]
	param (
		[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, Mandatory)]
		[ValidatePattern('^[0-9a-fA-F]{32}$')]
		[string]$CompressedGuid
	)
	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()
			[array]::Reverse($part)
			$Guid += $part -join ''
		}
		$Guid = $Guid.Insert(9,'-').Insert(14, '-').Insert(19, '-').Insert(24, '-')
		$Guid + '}'
	}
}

The post Convert a Product Code to a GUID appeared first on Adam, the Automator.


Viewing all articles
Browse latest Browse all 19

Trending Articles