-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSetPassword.ps1
31 lines (26 loc) · 1.1 KB
/
SetPassword.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
# Resets passwords for multiple users.
# User names are appended with an index, e.g. "user01"
$StartUserIndex=1
$EndUserIndex=20
$UserNamePrefix="user"
[Reflection.Assembly]::LoadWithPartialName("System.Web")
[Reflection.Assembly]::LoadWithPartialName("Regex")
function SetPassword ($name,$password) {
Set-ADAccountPassword -Identity "$name" -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$password" -Force)
echo "user: $name , password: $password"
}
function ResetPasswords() {
For ($i=$StartUserIndex; $i -le $EndUserIndex; $i++) {
$randomStr = [System.Web.Security.Membership]::GeneratePassword(6,0)
$randomStr = $randomStr -replace '[^a-zA-Z0-9]', (Get-Random -Minimum 0 -Maximum 10).ToString()
$prefix = "Cod3." # to meet AD upper/lower/num/symbol complexity policy.
$password = $prefix + $randomStr
$name = "$UserNamePrefix" + "$i".Padleft(2,'0')
Try {
SetPassword $name $password
} Catch [Exception] {
echo $_.Exception.GetType().FullName, $_.Exception.Message
}
}
}
ResetPasswords