SystemInfo - Get computer System Model via CMD - Extra spaces bug

Eliran Cohen picture Eliran Cohen · Apr 12, 2013 · Viewed 14.7k times · Source

I'm trying to get a Computer System Model type via Batch file. for this i've created this script:

systeminfo | find "System Model" > %temp%\TEMPSYSINFO.txt
for /F "tokens=2 delims=:" %%a in (%temp%\TEMPSYSINFO.txt) do set SYSMODEL=%%a
del %temp%\TEMPSYSINFO.txt
set SYSMODEL=%SYSMODEL:~1%
echo %SYSMODEL% >%temp%\SYSMODEL.txt
del %temp%\SYSMODEL.txt
set "Line1=*** System Model: %SYSMODEL%"
echo %Line1%

but when I run it i get extra spaces:

*** System Model:              OptiPlex 9010

Any idea how can I fix it?

Answer

rojo picture rojo · Apr 12, 2013

You're doing it the hard way. Use wmic. It's a lot faster and less complicated to scrape.

for /f "tokens=2 delims==" %%I in ('wmic computersystem get model /format:list') do set "SYSMODEL=%%I"
set "Line1=*** System Model: %SYSMODEL%"
echo %Line1%

wmic lets you query all sorts of neat wmi garbage. wmic /? for more info.

(updated per OP's comment under Fuzzy Button's answer)