Convert a GUID to a Compressed GUID with Powershell

Adam Bertram

Adam Bertram

Read more posts by this author.

I recently updated an old post that showed you how to convert a compressed GUID into a GUID. Here’s a sister post that shows you how to do the opposite; convert a GUID into a compressed GUID.

function Convert-GuidToCompressedGuid {
		This converts a GUID to a compressed GUID also known as a product code.	
		This function will typically be used to figure out the product code
		that matches up with the product code stored in the 'SOFTWARE\Classes\Installer\Products'
		registry path to a MSI installer GUID.
		Convert-GuidToCompressedGuid -Guid '{7C6F0282-3DCD-4A80-95AC-BB298E821C44}'
		This example would output the compressed GUID '2820F6C7DCD308A459CABB92E828C144'
		The GUID you'd like to convert.
	param (
		[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName, Mandatory)]
	begin {
		$Guid = $Guid.Replace('-', '').Replace('{', '').Replace('}', '')
	process {
		try {
			$Groups = @(
				$Guid.Substring(0, 8).ToCharArray(),
				$Guid.Substring(8, 4).ToCharArray(),
				$Guid.Substring(12, 4).ToCharArray(),
				$Guid.Substring(16, 16).ToCharArray()
			$Groups[0..2] | foreach {
			$CompressedGuid = ($Groups[0..2] | foreach { $_ -join '' }) -join ''
			$chararr = $Groups[3]
			for ($i = 0; $i -lt $chararr.count; $i++) {
				if (($i % 2) -eq 0) {
					$CompressedGuid += ($chararr[$i+1] + $chararr[$i]) -join ''
		} catch {
			Write-Error $_.Exception.Message	

Subscribe to Adam the Automator

Get the latest posts delivered right to your inbox

Looks like you're offline!