0

i have applied this batch script to display all information of my computer here i have getting errors on hdd and sdd like this below

how to correct this script can anyone help me on this

HDD:
3 - Invalid alias verb.
3 - Invalid alias verb.
Missing operand.
Missing operand.
Size:  GB
Free space:  GB

SSD:
2 - Invalid alias verb.
2 - Invalid alias verb.
Missing operand.
Missing operand.
Size:  GB
Free space:  GB

this is batch script i have used

@echo off

echo Processor:
wmic cpu get name

echo.
echo RAM:
wmic memorychip get capacity /value
set /a ram=0
for /f "tokens=2 delims==" %%i in ('wmic memorychip get capacity /value ^| find "Capacity"') do set /a ram+=%%i
set /a ramgb=%ram%/1024/1024/1024
echo %ramgb% GB

echo.
echo Motherboard:
wmic baseboard get product,manufacturer

echo.
echo HDD:
for /f "tokens=2 delims==" %%a in ('wmic logicaldisk where drivetype=3 get size /value ^| find "Size"') do set hddsize=%%a
for /f "tokens=2 delims==" %%a in ('wmic logicaldisk where drivetype=3 get freespace /value ^| find "FreeSpace"') do set hddfree=%%a
set /a hddsizegb=%hddsize%/1024/1024/1024
set /a hddfreegb=%hddfree%/1024/1024/1024
echo Size: %hddsizegb% GB
echo Free space: %hddfreegb% GB

echo.
echo SSD:
for /f "tokens=2 delims==" %%a in ('wmic logicaldisk where drivetype=2 get size /value ^| find "Size"') do set ssdsize=%%a
for /f "tokens=2 delims==" %%a in ('wmic logicaldisk where drivetype=2 get freespace /value ^| find "FreeSpace"') do set ssdfree=%%a
set /a ssdsizegb=%ssdsize%/1024/1024/1024
set /a ssdfreegb=%ssdfree%/1024/1024/1024
echo Size: %ssdsizegb% GB
echo Free space: %ssdfreegb% GB

echo.
pause

2
  • 2
    you have to escape the = as ^= (like you did with |) Commented Jan 6, 2023 at 10:06
  • 1
    (note: you didn't take care of potential more than one disk - your code only gets the data for the last found disk) Commented Jan 6, 2023 at 10:09

1 Answer 1

1

You don't consider having more than one disk in the system. Your for loops return the last found disk data only. Also, you shouldn't execute wmic for each desired data (wmic is quite slow, so you can improve performance by only executing it once)

Here is an example:

@ECHO off
setlocal enabledelayedexpansion
set i=0
for /f "skip=1 tokens=1-3" %%a in ('"wmic logicaldisk where drivetype=3 get freespace,name,size|findstr /v "^^$" "') do (
  set /a i+=1
  set "_Freespace[!i!]=%%a"
  set "_Name[!i!]=%%b"
  set "_Size[!i!]=%%c"
)
set _

Example output (on my system):

_Freespace[1]=21331169280
_Freespace[2]=1547910324224
_Freespace[3]=10803728384
_Freespace[4]=311614398464
_Name[1]=C:
_Name[2]=D:
_Name[3]=E:
_Name[4]=S:
_Size[1]=125791367168
_Size[2]=1973554245632
_Size[3]=26843541504
_Size[4]=960178941952

Also, be aware set /a works with INT32, which limits the range to 2GB. If the numbers for size or freespace are greater than that (very likely nowadays), you'll get an error message. You need another method for translating bytes into kB/MB/GB.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.