I need a windows command line script that takes an output, edits it and creates an environmental variable

1.2k views Asked by At

I have Asset tags embedded in BIOS. I use

wmic SYSTEMENCLOSURE get SMBiosAssetTag

This pulls the information I want but it is not formatted well:

SMBIOSAssetTag

11886

I need to just have those 5 numbers and nothing else. I will then use that variable to name the computer with a first logon script. I have spent hours on this, and I could have been done in 3 minutes if this was linux.

Note: I can't put linux tools on these builds :-(

3

There are 3 answers

0
LS_ᴅᴇᴠ On

Using

WMIC SYSTEMENCLOSURE GET SMBiosAssetTag /FORMAT:VALUE

will make a better output:

(some empty lines)
SMBIOSAssetTag=CZC1296FLD
(some empty lines)

So, in batch you may just

FOR /F "TOKENS=1,* DELIMS==" %%v IN (WMIC SYSTEMENCLOSURE GET SMBiosAssetTag /FORMAT:VALUE) DO IF /I "%%v" == "SMBIOSAssetTag" SET SMBIOSAssetTag=%%w

Side note: hard part in WMIC output is handling empty lines.

0
Monacraft On

This will work, tested it myself:

for /f "eol=S" %%a in ('wmic SYSTEMENCLOSURE get SMBiosAssetTag^|sort') do (set var=%%a)

It works fine.

Mona

0
Endoro On
for /f "delims=" %%a in ('wmic SYSTEMENCLOSURE get SMBiosAssetTag') do for /f %%b in ("%%a") do set "var=%%b"
echo %var%