Tuesday, August 11, 2009

Scripting - Find out how many users in a domain

I required a simple script to find out how many users are in an AD domain. Before creating one myself I looked and found one thats really easy and basic to use from windowsitpro.

http://windowsitpro.com/article/articleid/79302/jsi-tip-7262-how-many-users-exist-in-your-domain.html

Here is the batch script:

@echo off
setlocal
set /a numb=0
for /f "Skip=4 Tokens=*" %%i in ('net user /domain^|findstr /v /c:"----"^|findstr /v /i /c:"The command completed"') do (
set line=%%i
call :parse
)
@echo Number of users=%numb%
endlocal
goto :EOF
:parse
set name=%line:~0,25%
set /a numb=%numb% + 1
set name=%line:~25,25%
if not "%name%" EQU "" set /a numb=%numb% + 1
set name=%line:~50,25%
if not "%name%" EQU "" set /a numb=%numb% + 1

Just save it in a file with a bat extention and run it:

No comments:

Post a Comment