Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-Password {
- Param (
- [ValidateRange(8, 20)]
- [int] $PasswordLength = 14,
- [ValidateRange(1, 4)]
- [int] $MinimumSpecialCharacters = 3
- )
- # Specify the range of ASCII characters to use, avoiding ambiguous characters such as 0, O, o
- # also limit the allowed special characters to those which are easy to read
- $punc = 33..33 + 35..38 + 42..43 + 45..45
- $numbers = 50..57
- $letters = 65..78 + 80..90 + 97..110 + 112..122
- # Generate the list of required minimum special characters
- $password = Get-Random -Count $MinimumSpecialCharacters -InputObject $punc `
- |% -Begin { $aa = $null } `
- -Process { $aa += ([char]$_) } `
- -End { $aa }
- # Create the remainder of the password from any of the allowed characters
- $password += Get-Random -Count ($PasswordLength - $MinimumSpecialCharacters) -InputObject ($punc + $numbers + $letters) `
- |% -Begin { $aa = $null } `
- -Process { $aa += ([char]$_) } `
- -End { $aa }
- # Return the password but shuffled to ensure that the password doesn't always start with
- # special characters
- return -join ($password.ToCharArray() | Sort-Object { Get-Random })
- }
- Get-Password -PasswordLength 14 -MinimumSpecialCharacters 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement