PowerShell 技能连载 - 创建随机的密码

以下是另一小段用于生成由指定数量的大小写字母、数字,和特殊字符组成的随机密码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$length = 10
$length_small = $length - 3
$numbers = '2,3,4,5,6,7,8,9' -split ','
$large = 'A,B,C,D,E,F,G,H,K,L,M,N,P,R,S,T,U,V,W,X,Y,Z' -split ','
$small = 'A,B,C,D,E,F,G,H,K,L,M,N,P,R,S,T,U,V,W,X,Y,Z'.ToLower() -split ','
$special = '!,§,$,='.Split(',')

$password = @()
$password = @($numbers | Get-Random)
$password += @($large | Get-Random)
$password += @($small | Get-Random -Count $length_small)
$password += @($special | Get-Random)

$password = $password | Get-Random -Count $length

$password -join ''

本文国际来源:Creating Random Passwords

评论