-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-Password.ps1
66 lines (48 loc) · 1.21 KB
/
New-Password.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<#
.Synopsis
Creates a random password.
.DESCRIPTION
Generates a random password using ASCII printable characters.
.EXAMPLE
PS C:\> New-Password -Length 10
iEDQ5s}xoJ
.EXAMPLE
PS C:\> New-Password -LettersNumbersOnly
Z55Yjf1M4rSVNg4OCTaR
#>
function New-Password{
[CmdletBinding()]
Param
(
[Parameter(Position=0)]
[int]$Length=20,
[switch]$LettersNumbersOnly
)
Process{
$ascii=$null
if($LettersNumbersOnly){
for($a=48; $a –le 57; $a++){
$ascii+=,[char][byte]$a
}
for($a=65; $a –le 90; $a++){
$ascii+=,[char][byte]$a
}
for($a=97; $a –le 122; $a++){
$ascii+=,[char][byte]$a
}
for($i=1; $i –le $length; $i++){
$TempPassword+=($ascii | Get-Random)
}
$TempPassword
}
else{
for($a=33; $a –le 126; $a++){
$ascii+=,[char][byte]$a
}
for($i=1; $i –le $length; $i++){
$TempPassword+=($ascii | Get-Random)
}
$TempPassword
}
}
}