Skip to content

Instantly share code, notes, and snippets.

@larsks
Created November 4, 2012 13:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save larsks/4011916 to your computer and use it in GitHub Desktop.
Save larsks/4011916 to your computer and use it in GitHub Desktop.
Generating a random password using Get-Random
# Generate a random password
# Usage: random-password <length>
Function random-password ($length = 15)
{
$punc = 46..46
$digits = 48..57
$letters = 65..90 + 97..122
# Thanks to
# https://blogs.technet.com/b/heyscriptingguy/archive/2012/01/07/use-pow
$password = get-random -count $length `
-input ($punc + $digits + $letters) |
% -begin { $aa = $null } `
-process {$aa += [char]$_} `
-end {$aa}
return $password
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment