Skip to content

Instantly share code, notes, and snippets.

@codaamok
Last active January 20, 2026 20:12
Show Gist options
  • Select an option

  • Save codaamok/7ed30d01280ce28bb451621966707c1b to your computer and use it in GitHub Desktop.

Select an option

Save codaamok/7ed30d01280ce28bb451621966707c1b to your computer and use it in GitHub Desktop.
function Convert-CompressedGuidToProductCode {
param(
[Parameter(Mandatory)]
[string]$CompressedGuid
)
function Reverse-String ([array]$a) {
[String]::Join('', $a[-1..-($a.Count)])
}
function Reverse-Bytes ([String]$a) {
[String]::Join('', ($a -split '(..)' -ne '' -replace '(\w)(\w)','$2$1'))
}
$data1 = Reverse-String $CompressedGuid[0..7]
$data2 = Reverse-String $CompressedGuid[8..11]
$data3 = Reverse-String $CompressedGuid[12..15]
$data4 = Reverse-Bytes ($CompressedGuid[16..19] -join '')
$data5 = Reverse-Bytes ($CompressedGuid[20..31] -join '')
return '{0}-{1}-{2}-{3}-{4}' -f $data1, $data2, $data3, $data4, $data5
}
Convert-CompressedGuidToProductCode -CompressedGuid '96F071321C0420725210000010000000'
# Should return 23170F69-40C1-2702-2501-000001000000
function Convert-ProductCodeToCompressedGuid {
param(
[Parameter(Mandatory)]
[string]$ProductCode
)
function Reverse-String ([array]$a) {
[String]::Join('', $a[-1..-($a.Count)])
}
function Reverse-Bytes ([String]$a) {
[String]::Join('', ($a -split '(..)' -ne '' -replace '(\w)(\w)','$2$1'))
}
$ProductCode = $ProductCode -replace '\{|\}|\-'
$data1 = Reverse-String $ProductCode[0..7]
$data2 = Reverse-String $ProductCode[8..11]
$data3 = Reverse-String $ProductCode[12..15]
$data4 = Reverse-Bytes ($ProductCode[16..19] -join '')
$data5 = Reverse-Bytes ($ProductCode[20..31] -join '')
return '{0}{1}{2}{3}{4}' -f $data1, $data2, $data3, $data4, $data5
}
Convert-ProductCodeToCompressedGuid -ProductCode '{23170F69-40C1-2702-2501-000001000000}'
# Should return 96F071321C0420725210000010000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment