Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RandomPassword
- Function RandomPassword
- {
- param($length=8)
- # Declare new randomizer
- $rand = New-Object System.Random
- $new_password = ""
- # 48 - 57 [0-9]
- # 65 - 91 [A-Z]
- # 97 - 123 [a-z]
- $symbol = @("!","@","#","(",")",".","<",">","+","-","_")
- 1..$length | foreach {
- switch ($rand.Next(4))
- {
- 0 {$new_password = $new_password + [char]$rand.Next(48, 57)}
- 1 {$new_password = $new_password + [char]$rand.Next(65, 91)}
- 2 {$new_password = $new_password + [char]$rand.Next(97, 123)}
- 3 {$new_password += Get-Random $symbol}
- default {$new_password = $new_password + "?"}
- }
- }
- return $new_password
- }
Add Comment
Please, Sign In to add comment