Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
Last active June 20, 2026 08:43
Show Gist options
  • Select an option

  • Save gregjhogan/2350eb60d02aa759c9d269c3fc6265b1 to your computer and use it in GitHub Desktop.

Select an option

Save gregjhogan/2350eb60d02aa759c9d269c3fc6265b1 to your computer and use it in GitHub Desktop.
Generate random string in powershell
#lowercase letters/numbers only
-join ((48..57) + (97..122) | Get-Random -Count 32 | % {[char]$_})
# all characters
-join ((33..126) | Get-Random -Count 32 | % {[char]$_})
@robertocoratti

Copy link
Copy Markdown

you may consider also this
$b=[Byte[]]::new(32); [System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($b); $c=-join((65..90+97..122+48..57)|%{[char]$_}); -join($b|%{$c[$_%62]})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment