Generate a Random Password in PowerShell
Build a strong random password from printable ASCII characters.
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
!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-RandomEvidence: Used with -Count to select unique character codes without replacement.
Last verified: 2026-09-20 · Category: Security & Privacy
06Related solutions
Verify Code Signatures with Get-AuthenticodeSignature
Read the Authenticode signature status and signer of any executable or script in PowerShell.
Fix 'scripts is disabled on this system' with Set-ExecutionPolicy
Understand PowerShell's execution policy scopes and set the one that lets you run your own local scripts without gutting the security model.
Grep on Windows: Select-String
Search inside text files and logs with regex, returning file, line number and match.