Advertisement
Raimonds

PowerShell - random password gen

Sep 2nd, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $pswCharacters = 7
  2. $pswDigits = 4
  3. $pswSpecialChars = @("!","@","$")
  4. $pswUseSpecialChars = $true
  5.  
  6. function fnc_randomPsw
  7. {
  8.     $constants = ('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z')
  9.     $vowels = ('a', 'e', 'i', 'o', 'u')
  10.                        
  11.     $pswWord = ""
  12.                        
  13.     $useConstant = $true
  14.                        
  15.     for ($i = 1; $i -le $pswCharacters; $i++)
  16.     {
  17.         if ($useConstant)
  18.         {
  19.             $pswWord += Get-Random -InputObject $constants
  20.             $useConstant = $false
  21.         }
  22.         else
  23.         {
  24.             $pswWord += Get-Random -InputObject $vowels
  25.             $useConstant = $true
  26.         }
  27.     }
  28.                        
  29.     $pswWordUpper = $pswWord[0].ToString().ToUpper()
  30.     $pswWordFinal = $pswWordUpper + $pswWord.ToString().Remove(0, 1)
  31.                        
  32.     if ($pswUseSpecialChars)
  33.     {
  34.         $pswWordFinal += (Get-Random -InputObject $pswSpecialChars).ToString()
  35.     }
  36.                        
  37.     $pswNmbrs = ""
  38.     for ($i = 1; $i -le $pswDigits; $i++)
  39.     {
  40.         $pswNmbrs += (Get-Random -Minimum 0 -Maximum 9).ToString()
  41.     }
  42.                        
  43.     $pswWordFinal += $pswNmbrs
  44.                                
  45.     return $pswWordFinal
  46. }
  47.  
  48. fnc_randomPsw
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement