Jul 14

Complex Password Generator

Function Get-RandomPassword {
     param(
         $length = 10,
         $characters = 'abcdefghkmnprstuvwxyzABCDEFGHKLMNPRSTUVWXYZ123456789!"??$%&/()=?*+#_'
     )
     $random = 1..$length | ForEach-Object { Get-Random -Maximum $characters.length }
     $private:ofs=""
     [String]$characters[$random]
 }
 Function Randomize-Text {
     param(
         $text
     )
     $number = $text.length -1
     $indexes = Get-Random -InputObject (0..$number) -Count $number
     $private:ofs=''
     [String]$text[$indexes]
 }
 Function Get-ComplexPassword {
     $password = Get-RandomPassword -length 8 -characters 'abcdefghiklmnprstuvwxyz'
     $password += Get-RandomPassword -length 2 -characters '#*+)'
     $password += Get-RandomPassword -length 4 -characters '123456789'
     $password += Get-RandomPassword -length 6 -characters 'ABCDEFGHKLMNPRSTUVWXYZ'
     Randomize-Text $password
 }
 Get-ComplexPassword
Jul 14

365 Password Generator

This powershell script bulk generates passwords in a similar style as the password generator in Office 365.  The passwords begin with a capital letter, followed by 5 lower case letters, and 2 digits at the end.  You can modify the pattern to suite your needs (Note: It’s using the ASCII table ranges as the set it randomly chooses from).

Function Generate365PW
{
	Param($max = 1)
	For ($i = 0; $i -lt $max; $i++){
		$pw = Get-Random -Count 1 -InputObject ((65..72)+(74..75)+(77..78)+(80..90)) | % -begin {$UC=$null} -process {$UC += [char]$_} -end {$UC}
		$pw += Get-Random -Count 5 -InputObject (97..122) | % -begin {$LC=$null} -process {$LC += [char]$_} -end {$LC}
		$pw += Get-Random -Count 2 -InputObject (48..57) | % -begin {$NB=$null} -process {$NB += [char]$_} -end {$NB}
		write-output $pw
	}
}
Generate365PW 10