用 PowerShell 生成随机密码

从可打印 ASCII 字符中构造强随机密码。

Windows随机安全PowerShell低风险
运行这段一行命令,打印一个 20 位随机密码。

01命令

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

02作用说明

该表达式从 33 到 126 的可打印 ASCII 范围中不放回地选取 20 个字符码,转换成字符后拼接。由于 Get-Random 不放回抽样,字符不会重复。增大数量可获得更长密码。

03风险

风险低风险
使用条件Windows 10/11 with PowerShell 5.1 or PowerShell 7+
!注意: 方便但不能替代密码管理器;密码会留在回滚缓冲和命令历史中。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

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

最后验证: 2026-09-20 · 分类: 安全与隐私

06相关方案