1

I would like to run a command to set a computers description. I found that to get the model i can do

wmic computersystem get model

I am wondering how can i set the result of that line to be a variable called model that will later be part of the computer description?

1

1 Answer 1

2

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.
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .