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.


Here is the batch script:

@echo off
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%
goto :EOF
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