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?


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:


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
@echo %model%


  • skip=1 is used to skip the wmic header line.
  • goto :done is use to skip the wmic extra blank line.

Example output:



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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.