how can I set the result of the following command to be a variable called model?
wmic computersystem get model
The output of this is:
Model
VPCF22L1E
Note the extra blank line.
Use the following batch file (test.cmd):
@echo off
for /f "usebackq skip=1" %%i in (`wmic computersystem get model`) do (
set model=%%i
goto :done
)
:done
@echo %model%
Notes:
skip=1
is used to skip the wmic
header line.
goto :done
is use to skip the wmic
extra blank line.
Example output:
F:\test>test
VPCF22L1E
F:\test>
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- for /f - Loop command against the results of another command.
- set - Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.
- wmic - Windows Management Instrumentation Command.