Skip to content

Instantly share code, notes, and snippets.

@samurailink3
Last active April 11, 2020 11:37
Show Gist options
  • Save samurailink3/5453543 to your computer and use it in GitHub Desktop.
Save samurailink3/5453543 to your computer and use it in GitHub Desktop.
Command line batch files for unlocking user accounts. For the No-PowerShell version you will need the user's Distinguished Name and an admin account that can unlock accounts. For the PowerShell version, you will need the user's sAMAccountName and an admin account that can unlock accounts.The `unlock-ps.bat` file is easier to work with, but I inc…
@echo off
REM ABOUT: This file will unlock a user account that you specify on the command line.
REM REQUIREMENTS: Powershell with ActiveDirectory Module; Active Directory Account with Unlock permissions.
echo "This file will unlock a user who's username (sAMAccountName) you specify."
SET /P ADDomain=Your domain name:
SET /P AdminUser=Your admin username:
SET /P UserToUnlock=Username you would like unlocked:
runas /noprofile /user:%ADDomain%\%AdminUser% "%windir%\system32\WindowsPowerShell\v1.0\powershell.exe -command import-module ActiveDirectory; Unlock-ADAccount -Identity %UserToUnlock%"
pause
@echo off
REM ABOUT: This file will unlock a user account that you specify the DN of.
REM REQUIREMENTS: Active Directory Account with Unlock permissions; DN of user you would like to unlock.
SET /P ADDomain=Your domain name:
SET /P AdminUser=Your admin username:
SET /P UserDN=Full User DN you would like unlocked:
echo "This file will unlock a user who's DN you specify."
runas /noprofile /user:%ADDomain%\%AdminUser% "dsmod user \"%UserDN%\" -disabled no"
pause
@robinuniyal
Copy link

Thank You samurailink3, but I don't want to put Domain and Admin username every time, I had tried to rename the file but no luck, please help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment