Script for List the Drives with Size in Windows as Batch script

Script for list all the drives with size information in windows platform

Use steps as follows:

1. Save the below script as batch file with any name like diskinfo.bat

2. Go to the location of script placed:
 Cd D:\scripts

3. Open the command prompt windows and execute it with following command:
D:\scripts> diskinfo.bat localhost
4.  Output as follows:

Drive: C:
Total space: 266 GB
Free space : 221 GBDrive: D:
Total space: 482 GB
Free space : 482 GB

Script as follows:

IF "%~1"=="" goto help

@FOR /F "skip=1 tokens=1" %%x IN ('"WMIC /node:"%1" LOGICALDISK GET Name " ') DO (

@FOR /F "tokens=1-3" %%n IN ('"WMIC /node:"%1" LOGICALDISK GET Name,Size,FreeSpace | find /i "%%x""') DO ( @SET FreeBytes=%%n & @SET TotalBytes=%%p

SET TotalSpace=!TotalBytes:~0,-9!
SET FreeSpace=!FreeBytes:~0,-10!

SET /A TotalUsed=!TotalSpace! - !FreeSpace!

REM IF !TotalSpace! LSS 0 goto error

@echo Drive: %%x
@ECHO ===========================
@ECHO Total space: !TotalSpace! GB
@ECHO Free space : !FreeSpace! GB

REM @SET TotalSpace=
REM @SET FreeSpace=
REM @SET TotalUsed=
REM goto end
goto end
echo *** Invalid server or drive specified ***
goto help

echo diskfree.cmd
echo Queries remote server for free disk space.
echo Specify a MACHINENAME and a drive letter to be queried
echo Example:   diskfree.cmd MACHINENAME c:
goto end




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s