WMIC LogicalDIsk mb conversion

lo ahmed
lo ahmed used Ask the Experts™
on
is there anyways to display logicaldisk size and free space in mb or gb?
wmic command I am currently using:
WMIC LOGICALDISK where drivetype=3 get caption,size,FreeSpace

thank you
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
If you can live with dividing by powers of 1000 rather than powers of 1024, then I typically just chop off the right 9 digits to get a reasonable estimate of GB size.  Here's an example to get you started for your case, as a BAT file.

@echo off
setlocal EnableDelayedExpansion

for /f "skip=2 tokens=2-4 delims=," %%A in ('wmic LogicalDisk Where DriveType^=3 Get Caption^,FreeSpace^,Size /format:csv 2^>NUL') do (
    set Caption=%%A
    set Free=%%B
    set Size=%%C
    set Free=!Free:~0,-9!
    if "!Free!" EQU "" set Free=0
    set Size=!Size:~0,-9!
    if "!Size!" EQU "" set Size=0
    echo !Caption!, Free=!Free! GB, Size=!Size! GB
)

Open in new window


»bp
lo ahmedSystem Administrator

Author

Commented:
Thank you, I actually have tried this, however i already have an array in my code and inserting another array breaks it.
below you will see my full code, i have an array that allows me to access machine names within my txt file and run these commands on them remotely.

 @echo off

 setlocal enabledelayedexpansion
if exist C:\dell\%computername%.csv del C:\dell\%computername%.csv" 
set outputfile="C:\dell\%computername%.csv" 


for /F %%i in (C:\machines.txt) do (
wmic /node:%%i computersystem get name >> %outputfile%
wmic /node:%%i Cpu get Name >> %outputfile%
wmic /node:%%i path win32_VideoController get name >> %outputfile% 
WMIC /node:%%i LOGICALDISK where drivetype=3 get caption,size,FreeSpace >> %outputfile%
wmic /node:%%i ComputerSystem get TotalPhysicalMemory >> %outputfile%

)


goto :eof

Open in new window

IT / Software Engineering Consultant
Top Expert 2016
Commented:
Here is a way to handle that, and make it a bit more readable.

@echo off
setlocal EnableDelayedExpansion

set listfile=C:\machines.txt
set outputfile=C:\dell\%computername%.csv

(
  for /F "usebackq" %%i in ("%listfile%") do (
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i computersystem get name /format:csv 2^>NUL') do (
      echo ComputerSystem : %%A
    )
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i Cpu get Name /format:csv 2^>NUL') do (
      echo Cpu : %%A
    )
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i path win32_VideoController get name /format:csv 2^>NUL') do (
      echo VideoController : %%A
    )
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i ComputerSystem get TotalPhysicalMemory /format:csv 2^>NUL') do (
      echo TotalPhysicalMemory : %%A
    )
    echo Drives:
    for /f "skip=2 tokens=2-4 delims=," %%A in ('wmic /node:%%i LogicalDisk Where DriveType^=3 Get Caption^,FreeSpace^,Size /format:csv 2^>NUL') do (
      set Caption=%%A
      set Free=%%B
      set Size=%%C
      set Free=!Free:~0,-9!
      if "!Free!" EQU "" set Free=0
      set Size=!Size:~0,-9!
      if "!Size!" EQU "" set Size=0
      echo.  !Caption!, Free=!Free! GB, Size=!Size! GB
    )
  ) 
) > "%outputfile%"

Open in new window


»bp
lo ahmedSystem Administrator

Author

Commented:
great! after tweaking a few things it worked! Thank you!

@echo off
setlocal EnableDelayedExpansion

set listfile=C:\machines.txt
set outputfile=C:\dell\%computername%.csv

(
  for /F "usebackq" %%i in ("%listfile%") do (
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i computersystem get name /format:csv 2^>NUL') do (
      echo ComputerSystem : %%A  
  )
 for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i Cpu get Name /format:csv 2^>NUL') do (
echo Cpu : %%A
    )
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i path win32_VideoController get name /format:csv 2^>NUL')

do (
      echo VideoController: %%A
    )
    for /f "skip=2 tokens=2 delims=," %%A in ('wmic /node:%%i ComputerSystem get TotalPhysicalMemory /format:csv

2^>NUL') do (

      set TotalPhysicalMemory=%%A
      set TotalPhysicalMemory=!TotalPhysicalMemory:~0,-10!
            echo  TotalPhysicalMemory=!TotalPhysicalMemory! MB
   
    )
    echo Drives:
    for /f "skip=2 tokens=2-4 delims=," %%A in ('wmic /node:%%i LogicalDisk Where DriveType^=3 Get

Caption^,FreeSpace^,Size /format:csv 2^>NUL') do (
      set Caption=%%A
      set Free=%%B
      set Size=%%C
      set Free=!Free:~0,-10!
      set Size=!Size:~0,-10!
     echo  !Caption!, Free=!Free! MB, Size=!Size! MB
echo --------------------------------------------------------------------------------
    )
  )
) > "%outputfile%"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial