0

I'm creating a script to automatic update BIOS firmware for our Dell PC. We have multiple model here, so I need to check the model

C:\Users\me>wmic csproduct get name
Name
OptiPlex 3020

And also bios version

C:\Users\me>wmic bios get smbiosbiosversion
SMBIOSBIOSVersion
A09

Now I will put the bios updater somewhere on our network with filename format model_version.exe. How should I do to get the model and version in to 2 variables and in the end I just run

//path/to/the/updater/"%model%_%version%.exe" /s /r

to update the bios automatically, if the PC already on the latest bios version, just skip the script?

Thank a lot for your help.

Anh Luu
  • 13
  • 3
  • I would say that no one will do this for you; but someone probably will. – Grady Player Feb 22 '17 at 04:29
  • 2
    Possible duplicate of [Batch file set wmi output as a variable](http://stackoverflow.com/questions/20219527/batch-file-set-wmi-output-as-a-variable) – JosefZ Feb 22 '17 at 07:55
  • You must be renaming the executables in the server yourself. If so why would you name them with spaces, e.g.`Optiplex 3020_A14.exe` from name `O3020A14.exe` surely you'd name them using the easily identifiable name without the spaces, `Optiplex3020_A14.exe`. That said, your code would have to identify the version then check against the server held names than parse those names and identify if the version is lower than the version identified using WMI. Are you sure you don't want to update your question with more detail before your current question is closed for duplicating an existing question. – Compo Feb 22 '17 at 11:35
  • Windows uses backslashes for file paths. – Squashman Feb 22 '17 at 14:14
  • @Compo Yeah I need to check BIOS version from Dell support page manual, and rename it to right format for the script. – Anh Luu Feb 23 '17 at 08:54

1 Answers1

0

I recently had this same issue, needing to update a bunch of Acer laptops BIOS to fix the trackpads. Here is the solution I came up with, using the linked Batch file set wmi output as a variable from JosefZ's comment on your question.

By using /value switch of wmic we can get the wmic output on one line and then use 'for' with delims to tokenize it (split into two variables) and store the 2nd token as our desired variable.

Check if the file exists, then pass through to the "start" command so the bat file won't exit until after it has run the updater. (This is useful if combining with pushd to access a network path so the drive letter doesn't drop out)

for /f "tokens=2 delims==" %%f in ('wmic csproduct get name /value ^| find "="') do set "model=%%f"

for /f "tokens=2 delims==" %%f in ('wmic bios get smbiosbiosversion /value ^| find "="') do set "version=%%f"

IF EXIST "\\path\to\the\updater\%model%_%version%.exe" start "" /WAIT "\\path\to\the\updater\%model%_%version%.exe" /s /r
Andrew Fox
  • 96
  • 7