Skip to content

Instantly share code, notes, and snippets.

@JohnLBevan
Last active March 28, 2018 13:16
Show Gist options
  • Select an option

  • Save JohnLBevan/54e9e40ac5b6a7dbaba986d754f896e7 to your computer and use it in GitHub Desktop.

Select an option

Save JohnLBevan/54e9e40ac5b6a7dbaba986d754f896e7 to your computer and use it in GitHub Desktop.
function Compress-Guid {
[CmdletBinding()]
Param (
[Parameter(ValueFromPipeline = $true)]
[Guid]$Guid = [Guid]::NewGuid()
)
Process {
Write-Verbose "Received Guid $Guid"
[string]$GuidJustTheDigits = ($Guid.ToString() -replace '[{}-]','') #actually we don't need to replace {} since PS defaults to hyphens only formatting; but this does no harm / there's not much additional cost.
Write-Verbose "Just the digits length: $($GuidJustTheDigits.Length)" #32 chars
Write-Verbose "Just the digits: $GuidJustTheDigits"
$CompressedGuid = ($GuidJustTheDigits -split '(.{3})' | ?{$_} | %{'0x{0}' -f $_} | %{32 + [int]$_} | %{[char]$_}) -join ''
Write-Verbose "Length of Compressed Guid: $($CompressedGuid.Length )" #11 chars
Write-Verbose "Compressed GUID: $CompressedGuid"
$CompressedGuid
}
}
Compress-Guid -Verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment