Using DSQUERY, DSGET, and DSRM, I have scripted Disabled.bat to report all disabled user accounts, and optionally delete them.

The syntax for using Disabled.bat is:

Disabled \[/D\]

where /D is an optional parameter that will cause all disabled user accounts, that have a last name, to be deleted.

NOTE: Disabled.bat creates a Disabled.txt file in the current directory.

Disabled.bat contains:

@echo off
if not \{%1\}<h1><a name="_if_i_1_NEQ_D_echo_syntax_Disabled_D_amp_goto_EOF_setlocal_set_delete_N_if_not_1_">\{\} if /i \{%1\} NEQ \{/D\} @echo syntax: Disabled /D&goto :EOF
set delete=N
if not \{%1\}</a></h1>\{\} set delete=%1
if exist Disabled.txt del /q disabled.txt
for /f "Tokens=*" %%u in ('dsquery user -disabled') do set UDN=%%u&call :disa
goto :EOF
set LN=
for /f "Skip=1 Tokens=*" %%i in ('dsget user %UDN% -ln') do if /i "%%i" NEQ "dsget succeeded" set LN=%%i#
set LN=%LN:  #=%
set LN=%LN: #=%
set LN=%LN:#=%
if \{%LN%\} EQU \{\} goto :EOF
if /i "%delete%" NEQ "/D" goto report
call :del>nul 2>&1
if %ERRORLEVEL% EQU 0 goto report
@echo %UDN% failed to delete.>>Disabled.txt
goto :EOF
@echo %UDN%>>Disabled.txt
goto :EOF
dsrm %UDN% -noprompt