Guest User

Untitled

a guest
Mar 15th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. RandomPassword
  3.  
  4.  
  5. Function RandomPassword
  6. {
  7.     param($length=8)
  8.  
  9.     # Declare new randomizer
  10.     $rand = New-Object System.Random
  11.  
  12.     $new_password = ""
  13.  
  14.     # 48 - 57   [0-9]
  15.     # 65 - 91   [A-Z]
  16.     # 97 - 123  [a-z]
  17.     $symbol = @("!","@","#","(",")",".","<",">","+","-","_")
  18.  
  19.  
  20.     1..$length | foreach {
  21.         switch ($rand.Next(4))
  22.         {
  23.             0 {$new_password = $new_password + [char]$rand.Next(48, 57)}
  24.             1 {$new_password = $new_password + [char]$rand.Next(65, 91)}
  25.             2 {$new_password = $new_password + [char]$rand.Next(97, 123)}
  26.             3 {$new_password += Get-Random $symbol}
  27.             default {$new_password = $new_password + "?"}
  28.         }
  29.     }
  30.  
  31.     return $new_password
  32. }
Add Comment
Please, Sign In to add comment