Creating random passwords

by Apr 20, 2011

Take a look how easy it is for PowerShell to create random passwords:

PS > $list = [Char[]]'abcdefgABCDEFG0123456&%$'
PS > -join (1..20 | Foreach-Object { Get-Random $list -count 1 })
CbA3egDcgc55a064D50F
PS > -join (1..20 | Foreach-Object { Get-Random $list -count 1 })
406Bf2Fa6GE1a1Fe6Bfa
PS > -join (1..20 | Foreach-Object { Get-Random $list -count 1 })
DF%D$EDe1fB4&0B4EDg1

 

Simply create a list of allowable characters. Next, a loop will randomly pick characters out of that list, and -join will bind them together to a string. You can adjust the list of allowable characters to draw from  and then adjust the number of iterations to control the password length.

 

Twitter This Tip!
ReTweet this Tip!