Skip navigation

JSI Tip 9722. How can I return the drive letter, drive type, file system, disk label, size, free space, and free space percentage of a local or remote computers drives?


Using PsInfo.exe, I have scripted DriveInfo.bat to return the computer name, drive letter, drive type, file system, disk label, size, free space, and free space percentage of a local or remote computers drives, using a CSV format.

The syntax for using DriveInfo.bat is:

DriveInfo \[\\computername\]

Where \\computername is the optional remote computer name.

DriveInfo.bat contains:

@echo off
setlocal ENABLEDELAYEDEXPANSION
set comp=%1
if \{%1\}==\{\} set comp=\\%computername%
for /f "Skip=3 Tokens=*" %%a in ('psinfo Volume -d %comp%') do (
 set l=%%a
 set drive=!l:~0,1!
 set type=!l:~3,10!
 set type=!type: =!
 set fmt=!l:~14,10!
 set fmt=!fmt: =!
 set fmt=!fmt:,=;!
 if "!l:~14,1!" EQU " " set fmt=
 set lbl=!l:~25,20!
 set lbl=!lbl:  =!
 set lbl=!lbl: "="!
 if "!l:~25,1!" EQU " " set lbl=
 set size=!l:~46,10!
 set size=!size: =!
 set free=!l:~57,10!
 set free=!free: =!
 set freep=!l:~68,7!
 set freep=!freep: =!
 @echo "%comp:~2%","!drive!","!type!","!fmt!","!lbl!","!size!","!free!","!freep!"
)
endlocal



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish