Skip to content

Instantly share code, notes, and snippets.

@mwallner
Last active May 14, 2022 02:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwallner/379e0eb9dde98b7f893c2df2396a3191 to your computer and use it in GitHub Desktop.
Save mwallner/379e0eb9dde98b7f893c2df2396a3191 to your computer and use it in GitHub Desktop.
create a unique directory name based of system.guid
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment