-
Notifications
You must be signed in to change notification settings - Fork 1
/
New-GeneratedPassword.ps1
64 lines (59 loc) · 2 KB
/
New-GeneratedPassword.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
<#
.SYNOPSIS
Generates one or more random passwords
.DESCRIPTION
Generates one or more random passwords using [System.Web.Security.Membership]::GeneratePassword
.EXAMPLE
New-GeneratedPassword
.EXAMPLE
New-GeneratedPassword -Length 25 -MinNonAlpha 5
.EXAMPLE
New-GeneratedPassword -Length 25 -Count 10
#>
function New-GeneratedPassword {
[CmdletBinding()]
[OutputType([array])]
param(
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='The number of characters in the generated password. The length must be between 1 and 128 characters.')]
[ValidateRange(1,128)]
[int]$Length,
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='The minimum number of non-alphanumeric characters in the generated password(s).')]
[ValidateRange(1,128)]
[int]$MinNonAlpha,
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='The number of passwords to be generated.')]
[ValidateRange(1,100)]
[int]$Count
)
begin {
if(-not $Length) { [int]$Length = 15 }
if(-not $MinNonAlpha) { [int]$MinNonAlpha = 0 }
[Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
# Calling GeneratePassword Method
$list = @()
$i = 1
}
process {
if ($Count) {
while ($i -le $Count) {
# Write-Output "Current: $i -- Total: $multi"
$list += [System.Web.Security.Membership]::GeneratePassword($Length,$MinNonAlpha)
$i++
}
}
else {
$list += [System.Web.Security.Membership]::GeneratePassword($Length,$MinNonAlpha)
}
}
end {
return $list
}
}