Free and Simple Secure Password Generator in PowerShell

I needed a secure password generator for some project documentation. And I had been using online secure password generators like - Norton Password Generator - but then I found they all started getting blocked. Then I turned to Powershell, how hard could it be!? It turns out very easy.

This is the code I used directly in PowerShell:

$passwordlength = 31
$characterSet = [char[]](48..57) + [char[]](65..90) + [char[]](97..122) # 0..9 + A..Z + a..z
$password = (-join ((1..$passwordlength) | ForEach-Object { $CharacterSet | Get-Random })) + "!";$password

# Sample output:

ajRhZJtUaKp87dp4Qt9axPNCLjaVHfu!

$characterSet is just an array of characters.

  • ASCII 48 to 57 is 0 to 9
  • ASCII 65 to 90 is A to Z
  • ASCII 97 to 122 is a to z
If you want special characters check out:

My requirement was a 32 character passphrase, I have 31 random alphanumeric characters and add an exclamation mark (!) on the end as my one special character.

Comments