add a try block
Because of different password policies it makes sense to pack this function in a try block to let the user know if he's using a password which doesn't work
This commit is contained in:
parent
f381d38ee3
commit
e782225e8d
|
@ -11,18 +11,27 @@ Catch
|
|||
|
||||
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
|
||||
Read-Host 'Press a key to continue'
|
||||
Try
|
||||
{
|
||||
$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
|
||||
Read-Host 'Press a key to continue'
|
||||
}
|
||||
Catch
|
||||
{
|
||||
Write-Warning $_
|
||||
Read-Host 'Press a key to continue'
|
||||
Break
|
||||
}
|
||||
}
|
||||
|
||||
Reset-Password
|
||||
|
|
Reference in New Issue