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
|
function Reset-Password
|
||||||
{
|
{
|
||||||
$username = Read-Host 'Please enter a user name'
|
Try
|
||||||
$default_password = 'default-password'
|
{
|
||||||
Unlock-ADAccount -Identity $username
|
$username = Read-Host 'Please enter a user name'
|
||||||
Set-ADAccountPassword -Identity $username -Reset -NewPassword (
|
$default_password = 'default-password'
|
||||||
ConvertTo-SecureString -AsPlainText $default_password -Force
|
Unlock-ADAccount -Identity $username
|
||||||
)
|
Set-ADAccountPassword -Identity $username -Reset -NewPassword (
|
||||||
Set-ADuser $username -ChangePasswordAtLogon $True
|
ConvertTo-SecureString -AsPlainText $default_password -Force
|
||||||
Write-Host
|
)
|
||||||
Write-Host 'Password of ' $username 'reset to ' $default_password `
|
Set-ADuser $username -ChangePasswordAtLogon $True
|
||||||
-backgroundcolor green
|
Write-Host
|
||||||
Write-Host
|
Write-Host 'Password of ' $username 'reset to ' $default_password `
|
||||||
Read-Host 'Press a key to continue'
|
-backgroundcolor green
|
||||||
|
Write-Host
|
||||||
|
Read-Host 'Press a key to continue'
|
||||||
|
}
|
||||||
|
Catch
|
||||||
|
{
|
||||||
|
Write-Warning $_
|
||||||
|
Read-Host 'Press a key to continue'
|
||||||
|
Break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reset-Password
|
Reset-Password
|
||||||
|
|
Reference in New Issue