-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerate-ComplexPassword.ps1
54 lines (43 loc) · 1.08 KB
/
Generate-ComplexPassword.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
<#
.SYNOPSIS
Generates a complex long password
.DESCRIPTION
Generates a long password of $length with a number of $nonalphanumeric chars. Default is 12 char long with 2 nonalphanumeric chars.
.PARAMETER Length
Password length - Must be between 6-128
.PARAMETER NonAlpha
Number of non alphanumeric chars. Non alphanumber chars include: !@#$%^&*()_-+=[{]};:<>|./?.
.EXAMPLE
PS C:\> Generate-ComplexPassword -Length 14 -NonAlpha 4
PS C:\> xDQ;=Xr-P@K/.q
.EXAMPLE
PS C:\> ./Generate-ComplexPassword.ps1 8
PS C:\> ?Ekj!fOv
.INPUTS
None. No pipe input accepted
.OUTPUTS
System.String
.NOTES
Additional information about the function go here.
.LINK
http://about.me/steveawcooper
#>
[CmdletBinding()]
[OutputType([System.Int32])]
param(
[Parameter(Position=0)]
[ValidateRange(6,128)]
[System.Int32]
$Length = 12,
[Parameter(Position=1)]
[ValidateRange(0,127)]
[System.Int32]
$NonAlpha = 2
)
try {
Add-Type -Assembly System.Web
[Web.Security.Membership]::GeneratePassword($Length,$NonAlpha)
}
catch {
throw
}