(view source code of servers.bat as plain text)
@ECHO OFF
:: Servers.bat, Version 2.02 for Windows NT
:: List disk usage for all drives on all servers in tab delimited format.
:: Written by Rob van der Woude
:: http://www.robvanderwoude.com
:: For Windows NT 4 and Windows 2000 only
VER | FIND "Windows NT" >NUL
IF NOT ERRORLEVEL 1 GOTO Begin
VER | FIND "Windows 2000" >NUL
IF NOT ERRORLEVEL 1 GOTO Begin
GOTO VerErr
:Begin
TITLE %~nx0
ECHO.>CON
:: Make sure command extensions are active
VERIFY OTHER 2>NUL
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 GOTO CmdExtErr
:: Check if invalid switch was used, if so display usage
IF NOT [%1]==[] IF /I NOT [%1]==[/H] GOTO Syntax
:: Find servers and update the list if necessary
:: The FIND filter skips "servers" whose name start with \\PC
:: Adjust the FIND filter(s) to match your own situation
FOR /F "skip=3 eol=T tokens=1* delims= " %%A IN ('NET VIEW ^| FIND /I /V "\\PC"') DO CALL :AddSrv %%A
:: Display header line if /H switch was used
IF /I "%1"=="/H" (>CON ECHO Domain SrvType Server Drive Free Size Used MB/GB %% Free %% Used FS Volume)
IF /I "%1"=="/H" (>%~dpn0.dat ECHO Domain SrvType Server Drive Free Size Used MB/GB %% Free %% Used FS Volume)
:: Check all servers in the list
FOR /F "tokens=*" %%A IN ('TYPE %~dpn0.srv ^| FIND /V ";" ^| SORT') DO CALL :ChkSrv %%A
GOTO End
:AddSrv
:: Add server to the list if it isn't listed yet,
:: unless it is listed in the exclusion list
SET AddThisOne=1
IF EXIST %~dpn0.xcl FOR /F "tokens=*" %%a IN ('TYPE %~dpn0.xcl ^| FIND /V ";"') DO IF /I [%%a]==[%1] SET AddThisOne=0
IF EXIST %~dpn0.srv FOR /F "tokens=*" %%a IN ('TYPE %~dpn0.srv ^| FIND /V ";"') DO IF /I [%%a]==[%1] SET AddThisOne=0
IF %AddThisOne%==1 (>> %~dpn0.srv ECHO %1)
GOTO:EOF
:ChkSrv
SETLOCAL
SET Server=%1
SET Server=%Server:\=%
TITLE Checking %Server%
:: Determine server type
FOR /F "tokens=1* delims=:" %%K IN ('SRVINFO -ns %1 ^| FIND "NT Type:"') DO SET SrvType=%%L
ECHO.%SrvType% | FIND "NT Member Server" >NUL
IF NOT ERRORLEVEL 1 SET SrvType=SERVER
ECHO.%SrvType% | FIND "NT Advanced Server" >NUL
IF NOT ERRORLEVEL 1 (
SET SrvType=BDC
SRVINFO -ns %1 | FIND "PDC:" | FIND /I "%1" >NUL
IF NOT ERRORLEVEL 1 SET SrvType=PDC
)
:: Determine domain name
FOR /F "tokens=1* delims=: " %%K IN ('SRVINFO -ns %1 ^| FIND "Domain:"') DO SET Domain=%%L
:: Check all drives on the server
FOR /F "tokens=*" %%? IN ('SRVINFO -ns %1 ^| FIND "$"') DO CALL :ChkDrv %%?
ENDLOCAL
GOTO:EOF
:ChkDrv
:: Parse drive data
:: Delims is a TAB followed by a space
FOR /F "Tokens=1-4* delims= " %%k IN ("%*") DO (
SET Drive=%%k
SET FileSys=%%l
SET Size=%%m
SET Free=%%n
SET Used=%%o
)
:: Get volume label
:: Delims is a TAB followed by a space
FOR /F "tokens=5* delims= " %%k IN ('DIR \\%Server%\%Drive%\*.* ^| FIND /I "\\%Server%\%Drive%" ^| FIND "Volume"') DO SET Volume=%%l
:: Replace $ in drive letter by a colon
SET Drive=%Drive:$=%:
SET /A Round = %Size% / 2
SET /A PFree = 100 * %Free%
SET /A PFree = %PFree% + %Round%
SET /A PFree = %PFree% / %Size%
SET /A PUsed = 100 * %Used%
SET /A PUsed = %PUsed% + %Round%
SET /A PUsed = %PUsed% / %Size%
:: Display drive data
>CON ECHO.%Domain% %SrvType% %Server% %Drive% %Free% %Size% %Used% MB %PFree% %PUsed% %FileSys% %Volume%
>>%~dpn0.dat ECHO.%Domain% %SrvType% %Server% %Drive% %Free% %Size% %Used% MB %PFree% %PUsed% %FileSys% %Volume%
GOTO:EOF
:VerErr
ECHO This batch file was written for Windows NT 4 and 2000 only
GOTO End
:CmdExtErr
(ECHO Unable to enable command extensions) 1>&2
GOTO End
:Syntax
>CON ECHO Servers.bat, Version 2.02 for Windows NT
>CON ECHO List disk usage for all drives on all servers in tab delimited format.
>CON ECHO Written by Rob van der Woude
>CON ECHO http://www.robvanderwoude.com
>CON ECHO.
>CON ECHO Usage: SERVERS [ /H ^| /? ]
>CON ECHO. /H shows Header line
>CON ECHO. /? shows this help screen
>CON ECHO.
>CON ECHO This batch file uses 2 additional files:
>CON ECHO %~n0.srv contains a list of all server names to be checked, one server
>CON ECHO name per line, preceded by double backslashes; if this file
>CON ECHO does not exist, the batch file will create it.
>CON ECHO %~n0.xcl contains a list of all server names to be excluded, one server
>CON ECHO name per line, preceded by double backslashes. This file is
>CON ECHO optional: if it doesn't exist no servers are excluded.
>CON ECHO If a semi-colon is found anywhere in a line in these files, that line
>CON ECHO will be ignored.
>CON ECHO You may also add or adjust FIND filters in line 29 of this batch file
>CON ECHO to prevent workstations from being searched.
>CON ECHO Output is displayed on screen AND stored in a tab delimited ASCII file
>CON ECHO named %~n0.dat.
:End
ENDLOCAL
page last modified: 2024-04-16; loaded in 0.0102 seconds