Avatar of lo ahmed
lo ahmed
 asked on

WMIC LogicalDIsk mb conversion

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
* WMICWindows Batch

Avatar of undefined
Last Comment
lo ahmed

8/22/2022 - Mon
Bill Prew

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 ahmed

ASKER
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

ASKER CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lo ahmed

ASKER
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%"
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck