I'm trying to get info of the physical drives in a computer with wmic to get something like this:
Drive C:
500 GB Total
100 GB Free
20% Free
Drive D:
500 GB Total
100 GB Free
20% Free
My code so far is:
for /f "usebackq tokens=*" %%a in (`wmic logicaldisk where "drivetype=3" get caption`) do (
echo "Drive=%%a"
for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where DeviceID='%%a'"
get FreeSpace /format:value`) do set FreeSpace=%%x
for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where "DeviceID='%%a'" get Size /format:value`) do set Size=%%x
echo FreeMB=%FreeSpace%
echo SizeMB=%Size%
set /a Percentage=100 * %FreeSpace% / %Size%
echo %%a is %Percentage% %% free
)
And my output is:
"Drive=Caption
No Instance(s) Available.
No Instance(s) Available.
FreeMB=9193357312
SizeMB=80024170496
Invalid number. Numbers are limited to 32-bits of precision.
is % free
"Drive=C:
No Instance(s) Available.
No Instance(s) Available.
FreeMB=9193357312
SizeMB=80024170496
Invalid number. Numbers are limited to 32-bits of precision.
is % free
"Drive=E:
No Instance(s) Available.
No Instance(s) Available.
FreeMB=9193357312
SizeMB=80024170496
Invalid number. Numbers are limited to 32-bits of precision.
is % free
"Drive=
No Instance(s) Available.
No Instance(s) Available.
FreeMB=9193357312
SizeMB=80024170496
Invalid number. Numbers are limited to 32-bits of precision.
is % free
I'm getting to many lines that don't even have a drive and I can't format the value so I can calculate the percentage, or show the values in a normal format