(view source code of diskspc.bat as plain text)
@ECHO OFF
:: Check Windows version
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: Use variables locally
SETLOCAL
:: Check if FINDSTR and WMIC are available
FINDSTR.EXE /? >NUL 2>&1
IF ERRORLEVEL 1 (
ECHO ERROR: FINDSTR.EXE not found.
ECHO.
GOTO Syntax
)
WMIC.EXE /? >NUL 2>&1
IF ERRORLEVEL 1 (
ECHO ERROR: WMIC.EXE not found.
ECHO.
GOTO Syntax
)
:: Set default values
SET StartDir=%~dp0
SET Error=0
SET Format=TBL
SET Header=1
SET List=0
SET Node=%ComputerName%
SET ServerList=
:: Check command line arguments
IF NOT "%~4"=="" (
ECHO.ERROR: too many command line arguments: %*
ECHO.
GOTO Syntax
)
:: The command FOR %%A IN (/?) ... doesn't work, so we need a separate check on "?"
ECHO.%* | FIND.EXE "?" >NUL && GOTO Syntax
IF NOT "%~1"=="" (FOR %%A IN (%*) DO CALL :Parse %%A)
IF NOT "%Debug%"=="" (
SET StartDir
SET Error
SET Format
SET Header
SET List
SET Node
SET ServerList
)
:: Check validity of node name or existence of server list file
IF NOT "%ServerList%"=="" (CALL SET ServerList=%ServerList:^"=%)
IF "%ServerList%"=="" (
ECHO.%Node% | FINDSTR.EXE /R /C:"[/?*,;:/\\&<>+]" >NUL
IF NOT ERRORLEVEL 1 (
ECHO.ERROR: invalid characters in computer name: %*
ECHO.
SET Error=1
) ELSE (
PING %Node% -n 2 2>NUL | FIND "TTL=" >NUL
IF ERRORLEVEL 1 (
ECHO.ERROR: computer %Node% cannot be reached; check the
ECHO. computer name and/or if the computer is on-line
SET Error=1
)
)
) ELSE (
IF NOT EXIST "%ServerList%" (
ECHO.ERROR: file "%ServerList%" not found.
ECHO.
SET Error=1
)
)
IF "%List%"=="1" SET Node="@%ServerList%"
:: If any error occurred, show help text
IF "%Error%"=="1" GOTO Syntax
:: Query the specified computer(s)
IF "%Header%"=="0" (
IF "%Format%"=="CSV" WMIC.EXE /Node:%Node% LogicalDisk Where DriveType="3" Get DeviceID,FileSystem,FreeSpace,Size /Format:csv | MORE /E +2 | FINDSTR /R /C:"[ ,]"
IF "%Format%"=="TBL" WMIC.EXE /Node:%Node% LogicalDisk Where DriveType="3" Get DeviceID,FileSystem,FreeSpace,Size,SystemName /Format:table | MORE /E +1 | FINDSTR /R /C:"[ ,]"
) ELSE (
IF "%Format%"=="CSV" WMIC.EXE /Node:%Node% LogicalDisk Where DriveType="3" Get DeviceID,FileSystem,FreeSpace,Size /Format:csv | FINDSTR /R /C:"[ ,]"
IF "%Format%"=="TBL" WMIC.EXE /Node:%Node% LogicalDisk Where DriveType="3" Get DeviceID,FileSystem,FreeSpace,Size,SystemName /Format:table | FINDSTR /R /C:"[ ,]"
)
IF "%Format%"=="HTL" WMIC.EXE /Node:%Node% LogicalDisk Where DriveType="3" Get DeviceID,FileSystem,FreeSpace,Size,SystemName /Format:hform
IF "%Format%"=="HTT" WMIC.EXE /Node:%Node% LogicalDisk Where DriveType="3" Get DeviceID,FileSystem,FreeSpace,Size,SystemName /Format:htable
IF "%Format%"=="LST" WMIC.EXE /Node:%Node% LogicalDisk Where DriveType="3" Get DeviceID,FileSystem,FreeSpace,Size,SystemName /Format:list
:: Done
ENDLOCAL
GOTO:EOF
:Parse
SET Var=%~1
IF NOT "%Var:~0,1%"=="/" (
SET Node=%1
GOTO:EOF
)
IF /I NOT "%Var%"=="/C" IF /I NOT "%Var%"=="/HL" IF /I NOT "%Var%"=="/HT" IF /I NOT "%Var%"=="/L" IF /I NOT "%Var%"=="/NH" IF /I NOT "%Var%"=="/T" IF /I NOT "%Var:~0,3%"=="/SL" (
ECHO.ERROR: invalid command line switch: %1
ECHO.
SET Error=1
)
IF /I "%Var%"=="/C" SET Format=CSV
IF /I "%Var%"=="/HL" SET Format=HTL
IF /I "%Var%"=="/HT" SET Format=HTT
IF /I "%Var%"=="/L" SET Format=LST
IF /I "%Var%"=="/NH" SET Header=0
IF /I "%Var%"=="/T" SET Format=TBL
IF /I "%Var:~0,3%"=="/SL" SET List=1
IF NOT "%List%"=="1" GOTO:EOF
IF EXIST "%StartDir%servers.txt" SET ServerList=%StartDir%servers.txt
IF EXIST servers.txt SET ServerList=servers.txt
IF NOT "%Var:~3,1%"==":" IF NOT "%Var:~3,1%"=="" (
ECHO.ERROR: invalid command line switch: %1
ECHO.
SET Error=1
GOTO:EOF
)
IF "%Var:~3,1%"==":" SET ServerList=%Var:~4%
GOTO:EOF
:Syntax
ECHO.
ECHO DiskSpc.bat, Version 3.10 for Windows XP Professionaland later
ECHO Display disk usage for a (WMI enabled) computer or for a list of computers
ECHO.
ECHO Usage: DISKSPC [computer^|/SL[:listfile]] [/C^|/HL^|/HT^|/L^|/T] [/NH]
ECHO.
ECHO Where: "computer" is the computer to be checked (default is local system)
ECHO /SL use list of computers from text file
ECHO "listfile" is the name of a text file with one computer name per line
ECHO (default: "servers.txt" in current dir or batch's own dir)
ECHO /C output format CSV
ECHO /HL output format HTML List
ECHO /HT output format HTML Table
ECHO /L output format List
ECHO /T output format Table
ECHO /NH No Header line in CSV or Table output
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
IF "%OS%"=="Windows_NT" ENDLOCAL
EXIT /B 1
page last modified: 2024-04-16; loaded in 0.0073 seconds