解锁用户和重置密码的工具

时间:2015-04-24 20:27:56

标签: batch-file passwords unlock

我遇到了来自Spiceworks的批处理脚本来解锁用户和密码。

我没有提供输入用户名来解锁或重置密码的选项,而是预先定义用户名或用户名列表来解锁和重置密码。

例如以下内容。

Please choose a user to unlock or reset password:
(1) - John Doe
(2) - Bob smith
(3) - Kelly Brown
(4) - Vicky White


Here is the batch script from Spiceworks with some minor customization.

@echo Welcome to the tool to unlock users and reset passwords
@echo off
echo.
echo.
cd c:\
@echo NOTE: Username is not-case sensitive.
echo.
SET /P user=Please enter a username to unlock or reset password:
echo.

net user %user% /DOMAIN | FIND /I "account active"
echo.
@echo NOTE: The account will either be Locked "No" or active "Yes"
echo.
echo.

set /p userinp="Would you like to unlock this user?(Y/N)" %
IF "%userinp%"=="N" goto 2
IF "%userinp%"=="Y" goto 1 
IF "%userinp%"=="n" goto 2
IF "%userinp%"=="y" goto 1 


:end
echo.
@echo If you recieved errors while using this program
echo.
@echo 1. check the spelling of the username. 
@echo 2. Ensure that the password meets the policy requirements.
echo.
echo.
echo.
Pause
exit

:done
exit

:3
echo.
@echo NOTE: Password must be 12 characters including 1 uppercase letter, 1 special character, alphanumeric characters.
@echo Password is case sensitive
echo.
SET /P Password=Type a new password:
net user %user% %password% /DOMAIN
goto end


:2
set /p userinp="Would you like to reset the user's password?(Y/N)" %
echo.
If "%userinp%"=="N" Goto done
If "%userinp%"=="Y" Goto 3
If "%userinp%"=="n" Goto done
If "%userinp%"=="y" Goto 3


:1
echo.
Net user %user% /domain /active:YES
goto :2

1 个答案:

答案 0 :(得分:0)

将它与你所拥有的东西混合起来......

@echo off
setlocal
set user=
echo Please choose a user to unlock or reset password:
echo (1) - John Doe
echo (2) - Bob smith
echo (3) - Kelly Brown
echo (4) - Vicky White
:loop
set /p val=
if %val% equ 1 set user="John Doe"
if %val% equ 2 set user="Bob Smith"
if %val% equ 3 set user="Kelly Brown"
if %val% equ 4 set user="Vicky White"
if not defined user goto loop
echo %user%

稍微更高级的版本,以避免反复输入名称:

@echo off
setlocal enabledelayedexpansion
rem to add more names, just add the next number in the sequence
set option1=John Doe
set option2=Bob Smith
set option3=Kelly Brown
set option4=Vicky White

set user=
echo Please choose a user to unlock or reset password:
for /L %%a in (1,1,20) do (
    if x!option%%a! neq x (
        echo [%%a] - !option%%a!
        set maxval=%%a
    )
)
:loop
set /p val=
if x!option%val%! equ x goto loop
set user="!option%val%!"
echo %user%