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

Tool to unlock users and reset passwords

我从 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

将此与您所拥有的开始混合...

@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%