PowerShell Paul Fulbright PowerShell Paul Fulbright

PowerShell: Random Password Generator.

Quick little script to generate a password meeting simple complexity (guaranteed one upper and one number at random positions in the string) guidelines.

$upper = 65..90 | ForEach-Object{ [char]$_ }
$lower = 97..122 | ForEach-Object{ [char]$_ }
$number = 48..57 | ForEach-Object{ [char]$_ }
$total += $upper
$total += $number
$total += $lower
$rand = ""
$i = 0
while($i -lt 10){ $rand += $total | Get-Random; $i++ }
"Initial: "+$rand
$rand = $rand.ToCharArray()

$num = 1..$rand.Count | Get-Random
$up = $num
while($up -eq $num){ $up = 1..$rand.Count | Get-Random }

"num "+$num
"up "+$up
$rand[($num-1)] = $number | Get-Random
$rand[($up-1)] = $upper | Get-Random
$rand = $rand -join ""
"Final: "+$rand
Read More