Generate Random Passwords

The below was something that was created out of boredom to be honest.. Hope the script help for any purpose you see fit.

Function New-RandomPassword {
Param([int]$len=9 #how long a password do you want?
     )

[string]$s="12-34_5Abc:DeF;ghI<Jkl>MP=qrStUvwxYz67@#89$%0~!^no&"


$a=$s.toCharArray()
$x=""
for ($i=1;$i -le ($len*2);$i++) {
 $rand=$a[(Get-Random -min 0 -max $a.length)]
 if ($x -notmatch $rand) {
    $x+=$rand
  }
 }

$x.Substring(3,$len)
}

Published by iamfazul

Author of the site

Leave a comment