nbsp; if "!ERRORLEVEL!" == "0" (@echo 用户名 [%%a] 已经存在添加失败...
) else (@call :OK %%a %%b %%c %%d ...)
)
ping 127.0.0.1 -n 3 >nul
echo.
echo 命令完成,请按任意键退出...
pause >nul
start dsa.msc
goto:start
:OK
rem 延迟变量注意会抛弃所有!号
dsadd user "cn=%1,cn=users,dc=%Domain_name1%,dc=%Domain_name2%" -samid %2 -upn %3 -pwd %4 -pwdneverexpires yes -mustchpwd no >nul 2>nul
if not "!ERRORLEVEL!"=="0" (echo 用户Samid[%2]已经存在添加失败...) else (
echo 添加用户[%1]成功... )
echo.
goto :eof
:DelUsers
cls
echo [1]删除容器中单个用户
echo.
echo [2]删除组织单位中(OU)单个用户
echo.
echo [3]批量删除用户(不包括删除OU组织单位)
echo.
echo [4]批量删除用户(包括删除OU组织单位)
echo.
echo [5]返回上一个目录
set DelUs=
set /p DelUs="请输入你的选择:"
if "%DelUs%" == "1" goto Del_Singel
if "%DelUs%" == "2" goto Del_Ou
if "%DelUs%" == "3" goto Del_OuS1
if "%DelUs%" == "4" goto Del_OuS2
if "%DelUs%" == "5" goto start
echo 选择无效,请重新选择!
goto DelUsers
:Del_Singel
cls
set Singel=
set Cn_1=
set Domain_pname=
set /p Singel="请输入用户的DN(可分辨名称)(例如:John Smith):"
if "%Singel%" == "" echo 用户名不能为空,请重新输入! & pause>nul & goto Del_Singel
for /f "tokens=*" %%t in ('dsquery user -o dn ^|find /i "%Singel%"' ) do set Uesr=%%~t
echo %Uesr%
if "%Uesr%" == "" echo 此用户名不存在,请重新输入! & pause>nul & goto Del_Singel
pause
set /p Cn_1="请输入用户所在的容器名称(例如:users):"
if "%Cn_1%" == "" echo 容器名称不能为空,请重新输入! & pause>nul & goto Del_Singel
set /p Domain_pname="请输入你的域名(例如:microsoft.com):"
if "%Domain_pname%" == "" echo 域名不能为空,请重新输入! & pause>nul & goto Del_Singel
for /f "tokens=1,2 delims=." %%a in ("%Domain_pname%") do (set Domain_namep1=%%a
set Domain_namep2=%%b)
dsrm "cn=%Singel%,cn=%Cn_1%,dc=%Domain_namep1%,dc=%Domain_namep2%" -noprompt >nul
9 7 3 1 2 3 4 8 :