#define where the users are located in the AD
$OUsearchbase = 'OU=Users,DC=company,DC=nl','OU=Users2,DC=company,DC=nl','OU=Users3,DC=company,DC=nl'
#Select the right OU and User
$user = Get-ADUser -Filter * -Properties LockedOut -SearchBase (
$OUsearchbase | Out-GridView -PassThru -Title "Select the location of the user"
) |
Select-Object name,samaccountname,LockedOut,enabled |
Out-GridView -PassThru -Title "Select the user"
#Prompt for what action you would like to take
$title = "Choose Action"
$message = "What do you want to do to the user?"
$ResetPassword = New-Object System.Management.Automation.Host.ChoiceDescription "Reset Password", `
"Reset the users password"
$UnlockAccount = New-Object System.Management.Automation.Host.ChoiceDescription "Unlock account", `
"Unlock a locked user account"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($ResetPassword, $UnlockAccount)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
#take an action based on the selection
switch ($result)
{
0 {Set-ADAccountPassword -Identity $user.samaccountname -NewPassword (Read-Host -AsSecureString "Enter new password")}
1 {Unlock-ADAccount -Identity $user.samaccountname}
}