Is it possible to create a truly unique directory name (i.e. based on uuid) that is shorter then the default guid format?
so far I've been able to come up with this:
function Get-UglyButShortUniqueDirname {
[CmdletBinding()]
param ()
$t = "$([System.Guid]::NewGuid())".Replace("-", "")
Write-Verbose "base guid: $t"
$t = "$(0..$t.Length | % { if (($_ -lt $t.Length) -and !($_%2)) { [char][byte]"0x$($t[$_])$($t[$_+1])" } })".replace(" ", "").Trim()
Write-Verbose "guid as ascii: $t"
([System.IO.Path]::GetInvalidFileNameChars() | % { $t = $t.replace($_, '.') })
Write-Verbose "dirname: $t"
$t
}
With this I can generate directory names that look weird but take only about ~16 characters, which is way better than the default 32 characters of a plain guid (without dashes).
The thing I'm a bit concerned about: as 'invalid file name characters' are stripped and replaced with dots, those identifiers do not hold up to the same "uniqueness promise" as a guid does.
(struggling with legacy 260 char path-name limitations in Win-based automation environments :-/)