Active Directory unlock users script

Unlock Users

This is a lightweight tool for an easy way to manage the locked accounts in Active Directory that i grew very fond of.

Firstly this tool is made by Joe Richards so all hails to him, he has some other nice tools that you could use for windows servers day to day administration.

But for the purpose of our post download Unlock.exe

Put it in a folder of your choice but be aware that you might need to change the localization variables. I put it up in C:\Unlock\Unlock.exe

Download the script and save it as Unlock-Users.cmd

Than create a new shortcut and add target

C:\Windows\System32\cmd.exe /C “chcp 65001 && C:\Unlock\Unlock-Users.cmd”

@echo off
:: Unlock Users

setlocal
c:
cd \
cd unlock

:: Delete variables
set _user=

:_begin
cls
echo.
echo.
echo ************************************************
echo *                 Unlock Users                 *
echo *                 Terminal.ovh                 *
echo ************************************************
echo.
echo **************************************************************************
echo *        With This Program you can mannage locked AD Accounts            *
echo **************************************************************************

:_command
cls
echo.
echo.
echo.
echo *** Choose Command : ***
echo.
echo ** --- To see all locked accounts, choose "V" (View)
echo ** --- To unlock all locked accounts, choose "U" (Unlock)
echo ** --- To unlock only a chosen account, choose "K"(Choosen_Account)
echo.
echo ** --- To Exit, Choose "X" (Exit)
echo.
echo =================================================
echo.
SET /P _confirm=** INPUT "V", "U", "K" (Big or small letters): 

if "%_confirm%" == "v" cls & goto _view
if "%_confirm%" == "V" cls & goto _view
if "%_confirm%" == "u" cls & goto _unlock
if "%_confirm%" == "U" cls & goto _unlock
if "%_confirm%" == "k" cls & goto _choosen_account
if "%_confirm%" == "K" cls & goto _choosen_account
if "%_confirm%" == "x" cls & goto _exit
if "%_confirm%" == "X" cls & goto _exit

goto _command

:_view
cls
echo.
echo.
echo.
echo *** List of locked accounts: ***
echo.
echo.
Unlock.exe . * -view
echo.
echo.
ping 127.0.0.1 /n 5 > nul
goto :_command

:_unlock
cls
echo.
echo.
echo.
echo *** Unlocking all locked accounts ***
echo.
echo.
Unlock.exe . *
echo.
echo.
ping 127.0.0.1 /n 5 > nul
goto :_command

:_choosen_account
cls
echo.
echo.
echo.
echo *** Unlock only chosen account ***
echo.
echo *** List of locked accounts: ***
Unlock.exe . * -view
echo.
echo =============================
SET /P _user=** Input account (same as in the list):
if errorlevel 1 goto _choosen_account
echo =============================
echo.
echo.
Unlock.exe . %_user%
echo.
echo.
echo Press any key to continue ...
pause >nul
goto :_command


:_exit

:: Deleting all variables
set _user=

endlocal
goto :eof