-
-
Save gr4z/9d395d8835d53ad9dba9914c7530c33d to your computer and use it in GitHub Desktop.
Generating a random password using Get-Random
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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