vendredi 4 mai 2018

Windows batch - wmic computersystem get model - multiple models

i have a question simular to Windows Batch : query wmic computersystem get model if equals true continue with windows batch

I have a batch file that uses wmic to get the system model number and will need to run a script based on the model number

Here is my script

REM @echo off
setlocal enableextensions disabledelayedexpansion

for /f "tokens=2 delims==" %%a in (
    'wmic computersystem get model /value'
) do for /f "delims=" %%b in ("%%~a") do for %%m in (
    "HP t520 Flexible Series TC" "HP t610 WW Thin Client" "HP t620 Quad Core TC" "HP t630 Thin Client"
) do if /i "%%~b"=="%%~m" (
    set "model=%%~m"
    goto start
)

echo un-compatible system
goto :eof
:start
echo Start of script for model [%model%]
if [%model%]==[t520] start "" "C:\SWSetup\APP\Scripts\t520.bat" "C:\SWSetup\APP\Scripts\t520-wmi.bat"
if [%model%]==[t610] start "" "C:\SWSetup\APP\Scripts\t610.bat" "C:\SWSetup\APP\Scripts\t610-wmi.bat"
if [%model%]==[t620] start "" "C:\SWSetup\APP\Scripts\t620.bat" "C:\SWSetup\APP\Scripts\t620-wmi.bat"
if [%model%]==[t630] start "" "C:\SWSetup\APP\Scripts\t630.bat" "C:\SWSetup\APP\Scripts\t630-wmi.bat"

Here is the output of the cmd window

C:\SWSetup\APP\Scripts>setlocal enableextensions disabledelayedexpansion

C:\SWSetup\APP\Scripts>for /F "tokens=2 delims==" %a in ('wmic computersystem get model /value') do for /F "delims=" %b in ("%~a") do for %m in ("HP t520 Flexible Series TC" "HP t610 WW Thin Client" "HP t620 Quad Core TC" "HP t630 Thin Client") do if /I "%~b" == "%~m" (set "model=%~m"
goto start
)

") do for %m in ("HP t520 Flexible Series TC" "HP t610 WW Thin Client" "HP t620Quad Core TC" "HP t630 Thin Client") do if /I "%~b" == "%~m" (set "model=%~m"
goto start
)

C:\SWSetup\APP\Scripts>for %m in ("HP t520 Flexible Series TC" "HP t610 WW Thin Client" "HP t620 Quad Core TC" "HP t630 Thin Client") do if /I "HP t520 Flexible Series TC" == "%~m" (set "model=%~m"
goto start
)

C:\SWSetup\APP\Scripts>if /I "HP t520 Flexible Series TC" == "HP t520 Flexible Series TC" (set "model=HP t520 Flexible Series TC" 
goto start
)

C:\SWSetup\APP\Scripts>echo Start of script for model [HP t520 Flexible Series TC] Start of script for model [HP t520 Flexible Series TC] t520 was unexpected at this time.

C:\SWSetup\APP\Scripts>if [HP t520 Flexible Series TC]==[t520] start "" "C:\SWSetup\APP\Scripts\t520.bat" "C:\SWSetup\APP\Scripts\t520-wmi.bat"

What am I missing here?

Aucun commentaire:

Enregistrer un commentaire