Creating Temporary Passwords

by May 9, 2016

A good temporary password should be complex, yet unambiguous. So it should contain a mixture of upper and lower case plus special characters, but it should avoid conflicting characters such as "o", "O", and "0".

Here is sample code to get you started. Feel free to refine your personal temp password generator!

function Get-TempPassword
    $Length = 15
  $upper = [Char[]](65..90) -ne 'O' -ne 'Q' -ne 'L' -ne 'I'
  $lower = [Char[]](97..122) -ne 'o' -ne 'q' -ne 'l'
  $special = [Char[]]'§&"/+#*'

  $bucket = New-Object -TypeName System.Collections.ArrayList
  $null = $bucket.Add((Get-Random -Maximum 10))
  $null = $bucket.Add((Get-Random -Count 1 -InputObject $special))
  (Get-Random -Count (($length-2) /2) -InputObject $upper ).Foreach{$null = $bucket.Add($_)}
  (Get-Random -Count (($length-2) /2) -InputObject $lower ).Foreach{$null = $bucket.Add($_)}

  $bucket =  Get-Random -Count $length -InputObject $bucket 

  -join $bucket 

Twitter This Tip! ReTweet this Tip!