Search code examples
batch-filewmic

Batch scripting - echo device vendor and model with formatted output?


I'm trying to get my batch file to output the Vendor name and model of my Laptop, but I can't seem to get it formatted. Can someone help me to find a solution?

EDIT: Thank you for the answers, all of them work as I need it!

This is what I've got:

@echo off
set /a cnt=0
echo|set/p "=Vendor: "
for /f "tokens=* delims=" %%i in ('wmic csproduct get vendor') do (echo|set/p "=%%i")
set /a cnt=0
echo:
echo|set/p "=Name: "
for /f "tokens=* delims= " %%j in ('wmic csproduct get name') do (echo|set/p "=%%j ")
echo:
pause

Output:

Vendor: Vendor  HP
Name: Name                         HP EliteDesk 800 G3 DM 35W

My desired Output would be this:

Vendor: HP
Name: HP EliteDesk 800 G3 DM 35W

Solution

  • May I suggest a slightly different version?

    @echo off
    echo|set/p "=Vendor: "
    for /f "tokens=2 delims==" %%i in ('wmic csproduct get vendor /value') do (echo|set/p "=%%i")
    echo:
    echo|set/p "=Name: "
    for /f "tokens=2 delims==" %%i in ('wmic csproduct get name /value') do echo|set /p "=%%i"
    echo:
    pause
    

    /value avoids the spaces for formatting as a table.