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
lo ahmedSystem AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
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 AdministratorAuthor 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

Bill PrewIT / Software Engineering ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lo ahmedSystem AdministratorAuthor 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%"
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WMIC

From novice to tech pro — start learning today.