0

I am trying to run the following script

@ECHO OFF
FOR /F "Skip=1 Tokens=*" %%G IN ('WMIC COMPUTERSYSTEM GET Manufacturer') DO (SET "DeviceOEM=%%G")
ECHO OEM: %DeviceOEM%
PAUSE

However all I get is "ECHO OEM:", which indicates that %DeviceOEM% is blank.

Now if I run

FOR /F "Skip=1 Tokens=*" %%G IN ('WMIC COMPUTERSYSTEM GET Manufacturer') DO (ECHO %%G)
PAUSE

Then I get a real answer of my OEM.

I don't understand where this SET command is failing.

Sargon
  • 25
  • 5
  • For the reason of getting the environment variable not defined with the value as expected by you see my answer on [How to correct variable overwriting misbehavior when parsing output?](https://stackoverflow.com/a/24965431/3074564) There are multiple solutions for this problem. Which one is best depends on which __WMIC__ command line is used to get which data. – Mofi Apr 01 '22 at 11:26

1 Answers1

1

When delim is issued on = it will only assign the value after the = to the value. We therefore change the wmic command to issue the result with /value which will return Manufacturer=<name of OEM> where we only use everything post =

@echo off
For /F "tokens=2*delims==" %%G in ('WMIC COMPUTERSYSTEM GET Manufacturer /value') do SET "DeviceOEM=%%G"
echo OEM: %DeviceOEM%
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • Thank you for the updated answer with an explanation. It's simpler and does not add quotation marks to the variable. I'll have to remember the "/value" parameter. – Sargon Apr 01 '22 at 11:41
  • It is easy to remember that. Just bookmark this question. It is on the left of your question below the up/downvote area. – Gerhard Apr 01 '22 at 11:48