29 lines
637 B
PowerShell
29 lines
637 B
PowerShell
# load ActiveDirectory module
|
|
Try
|
|
{
|
|
Import-Module ActiveDirectory -ErrorAction Stop
|
|
}
|
|
Catch
|
|
{
|
|
Write-Warning $_
|
|
Break
|
|
}
|
|
|
|
function Reset-Password
|
|
{
|
|
$username = Read-Host 'Please enter a user name'
|
|
$default_password = 'default-password'
|
|
Unlock-ADAccount -Identity $username
|
|
Set-ADAccountPassword -Identity $username -Reset -NewPassword
|
|
(
|
|
ConvertTo-SecureString -AsPlainText $default_password -Force
|
|
)
|
|
Set-ADuser $username -ChangePasswordAtLogon $True
|
|
Write-Host
|
|
Write-Host 'Password of ' $username 'reset to ' $default_password `
|
|
-backgroundcolor green
|
|
Write-Host
|
|
|
|
}
|
|
|