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:

@ECHO OFF
IF "%~1"=="" goto help
@SETLOCAL ENABLEEXTENSIONS
@SETLOCAL ENABLEDELAYEDEXPANSION

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

@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.
@echo.
@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
:error
echo.
echo *** Invalid server or drive specified ***
echo.
goto help

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

:end

 

Advertisements

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s