Guest User

Untitled

a guest
Sep 14th, 2018
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. Write-Host "Password Reset and Unlock Tool`n" -ForegroundColor Yellow
  2.  
  3. $User = Read-Host "Enter in a Username"
  4. try{
  5. Get-ADuser $User -properties * | select Name,LockedOut,Enabled,@{n='Password Last Reset';e={$_.PasswordLastSet}},@{n="Job Title";e={$_."Description"}},@{n='Email';e={$_."EmailAddress"}},TelephoneNumber,Office | fl
  6. $Name = (Get-ADUser $User -Properties Name).name
  7. }
  8. catch{
  9. Write-Warning "$User is incorrect or does not exist.`nTry again"
  10. \\FileOfYourScript.ps1
  11. }
  12.  
  13. try{
  14. $Manager = (get-aduser (get-aduser $User -Properties manager).manager).samaccountname
  15. Get-ADUser $Manager -Properties * | Select @{n="Managers Name";e={$_."Name"}},@{n='Managers Email';e={$_."EmailAddress"}},@{n='Managers Number';e={$_."TelephoneNumber"}} | fl
  16. }
  17. catch{
  18. Write-Host "Manager info not set in AD" -ForegroundColor Yellow
  19. }
  20.  
  21.  
  22. $Correct = Read-Host "Is this the correct user? Y or N"
  23. if ($Correct -eq 'y') {
  24. if (((get-aduser $user -Properties LockedOut).LockedOut -eq $true) -or ((get-aduser $user -Properties Enabled).Enabled -eq $false)){
  25. Write-Warning "Account for $Name appears to be locked"
  26. $Lockout = Read-Host "Would you like to unlock $Name ? Y or N"
  27. if ($Lockout -eq 'Y'){
  28. try{
  29. Enable-ADAccount $User
  30. Unlock-ADAccount $User
  31. Write-Host "Sucessfully unlocked account for $Name" -ForegroundColor Green
  32. }
  33. catch{
  34. Write-Warning "Unable to unlock account for $Name, Try again"
  35. \\FileOfYourScript.ps1
  36. }
  37. }
  38. else{
  39. Write-Warning "Account unlock not selected"
  40. }
  41. }
  42. else{
  43. Write-Host "$Name's Account is not locked or disabled" -ForegroundColor Green
  44. }
  45.  
  46.  
  47. $Reset = Read-Host "Would you like to reset $Name's password? Y or N"
  48. if ($Reset -eq 'Y'){
  49. Write-Warning "Make sure to verify last 4 #s of Social"
  50. $Match = Read-Host "Do the last 4 digits of the Social match?"
  51. if ($Match -eq 'y'){
  52. try{
  53. $Password = ConvertTo-SecureString -AsPlainText "Password1" -Force ##Temp Password
  54. Write-Output "Resetting Password to Password1"
  55. Set-ADAccountPassword $User -NewPassword $Password -Reset #Sets new password
  56. Set-ADUser $User -ChangePasswordAtLogon $true #Makes user reset password at logon
  57. Write-Host "Password has been reset. $Name must change password at next login`n" -ForegroundColor Green
  58. }
  59. catch{
  60. Write-Warning "Unable to reset password maybe due to a permission issue`nReopening script..."
  61. Start-Sleep -Seconds 1
  62. }
  63. }
  64. else{
  65. Write-warning "Password not reset"
  66. }
  67.  
  68. }
  69.  
  70. else{
  71. Write-Warning "Password not reset"
  72. }
  73.  
  74. \\FileOfYourScript.ps1
  75. }
  76.  
  77. else{
  78. Write-Host "Reopening script..."
  79. \\FileOfYourScript.ps1
  80. }
Add Comment
Please, Sign In to add comment