Generate a Random Password in PowerShell

Build a strong random password from printable ASCII characters.

WindowsrandomsecuritypowershellLow risk
Run the one-liner to print a 20-character random password.

01Command

Command
$ -join ((33..126) | Get-Random -Count 20 | ForEach-Object {[char]$_})

02What it does

The expression selects 20 unique character codes from the printable ASCII range 33 to 126, converts each to a character and joins them. Because Get-Random draws without replacement, characters do not repeat. Increase the count for longer passwords.

03Risk

RiskLow risk
RequirementsWindows 10/11 with PowerShell 5.1 or PowerShell 7+
!Warning: This is convenient but not a substitute for a password manager; the value is printed in scrollback and shell history.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Get-Random
    Microsoft Learn · vendor-doc · 2026-09-20
    Evidence: Used with -Count to select unique character codes without replacement.

Last verified: 2026-09-20 · Category: Security & Privacy

06Related solutions