Guest User

Untitled

a guest
Jun 1st, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. FUNCTION RESET-USERPWD {
  2. $menu = @{}
  3. $x = 0
  4. $user = Read-Host "Please Type part of the user's Last Name"
  5. $pname = "*$USER*"
  6. $find = @(Get-ADUser | Sort-Object Name Name -Filter {name -like $pname} -Properties *)
  7. Write-host "0. Exit"
  8. for ($i=1;$i -le $find.count; $i++) {
  9. Write-Host "$i. $($find[$i-1].name,$find[$i-1].employeeID)"
  10. $menu.Add($i,($find[$i-1].samaccountname))
  11. }
  12. [int]$ans = Read-Host 'Enter the # for your selection'
  13. $selection = $menu.Item($ans)
  14. if ($ans -eq $x)
  15. { 'No User Account Password Reset'}
  16. else
  17. {
  18. $y = (Get-ADUser -Identity $selection -Properties employeeid)
  19. $z = 'M4K1-abc-'
  20. $ID = $y.EmployeeID
  21. Unlock-ADAccount -Identity $selection
  22. Set-adaccountpassword $selection -reset -newpassword (ConvertTo-SecureString -AsPlainText $Z$ID -Force)
  23. Set-aduser $selection -changepasswordatlogon $true
  24. Write-Host "User's Password has been changed to $Z$ID"
  25. }
  26. }
Add Comment
Please, Sign In to add comment