-
Notifications
You must be signed in to change notification settings - Fork 0
/
New-Password.ps1
39 lines (36 loc) · 898 Bytes
/
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
function New-Password {
[CmdletBinding()]
param (
[Parameter()]
[int]$PasswordLength = 10,
[Parameter()]
[switch]$UpperCase,
[Parameter()]
[switch]$LowerCase,
[Parameter()]
[switch]$Numeric,
[Parameter()]
[switch]$Special
)
$Password =
if ($UpperCase) {
$Password += ($UpperCaseSet = 'A'..'Z')
}
if ($LowerCase) {
$Password += ($LowerCaseSet = 'a'..'z')
}
if ($Numeric) {
$Password += ($NumericSet = '0'..'9')
}
if ($Special) {
$Password += ($SpecialSet = '!@#$%&*'.ToCharArray())
}
$RetrieveSets = $UpperCaseSet + $LowerCaseSet + $NumericSet + $SpecialSet
if ($Password) {
$Password = ($RetrieveSets | Get-Random -Count $PasswordLength) -join ''
$Password
}
else {
Get-Help New-Password
}
}