Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FUNCTION RESET-USERPWD {
- $menu = @{}
- $x = 0
- $user = Read-Host "Please Type part of the user's Last Name"
- $pname = "*$USER*"
- $find = @(Get-ADUser | Sort-Object Name Name -Filter {name -like $pname} -Properties *)
- Write-host "0. Exit"
- for ($i=1;$i -le $find.count; $i++) {
- Write-Host "$i. $($find[$i-1].name,$find[$i-1].employeeID)"
- $menu.Add($i,($find[$i-1].samaccountname))
- }
- [int]$ans = Read-Host 'Enter the # for your selection'
- $selection = $menu.Item($ans)
- if ($ans -eq $x)
- { 'No User Account Password Reset'}
- else
- {
- $y = (Get-ADUser -Identity $selection -Properties employeeid)
- $z = 'M4K1-abc-'
- $ID = $y.EmployeeID
- Unlock-ADAccount -Identity $selection
- Set-adaccountpassword $selection -reset -newpassword (ConvertTo-SecureString -AsPlainText $Z$ID -Force)
- Set-aduser $selection -changepasswordatlogon $true
- Write-Host "User's Password has been changed to $Z$ID"
- }
- }
Add Comment
Please, Sign In to add comment