Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. function Get-Password {
  2. Param (
  3. [ValidateRange(8, 20)]
  4. [int] $PasswordLength = 14,
  5.  
  6. [ValidateRange(1, 4)]
  7. [int] $MinimumSpecialCharacters = 3
  8. )
  9.  
  10. # Specify the range of ASCII characters to use, avoiding ambiguous characters such as 0, O, o
  11. # also limit the allowed special characters to those which are easy to read
  12. $punc = 33..33 + 35..38 + 42..43 + 45..45
  13. $numbers = 50..57
  14. $letters = 65..78 + 80..90 + 97..110 + 112..122
  15.  
  16. # Generate the list of required minimum special characters
  17. $password = Get-Random -Count $MinimumSpecialCharacters -InputObject $punc `
  18. |% -Begin { $aa = $null } `
  19. -Process { $aa += ([char]$_) } `
  20. -End { $aa }
  21.  
  22. # Create the remainder of the password from any of the allowed characters
  23. $password += Get-Random -Count ($PasswordLength - $MinimumSpecialCharacters) -InputObject ($punc + $numbers + $letters) `
  24. |% -Begin { $aa = $null } `
  25. -Process { $aa += ([char]$_) } `
  26. -End { $aa }
  27.  
  28. # Return the password but shuffled to ensure that the password doesn't always start with
  29. # special characters
  30. return -join ($password.ToCharArray() | Sort-Object { Get-Random })
  31. }
  32.  
  33. Get-Password -PasswordLength 14 -MinimumSpecialCharacters 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement