I am trying to figure out why my batch script doesn't work properly. It is calling wmic to see what server model it is and then deploy a set of drivers to that specific model number.
The 'wmic csproduct get name' outputs:
C:\>wmic csproduct get name
Name
ProLiant DL360p Gen8
The for command outputs:
C:\>FOR /F "tokens=3" %A IN ('wmic csproduct get name') DO ( echo %A)
C:\>(echo Gen8 )
Gen8
Here is the script:
ECHO !TIME! - Determining if this is a HP Gen 8 or 9 server... >> !LOGFILE!
wmic csproduct get name | FIND /i "Gen" >NUL
if %ERRORLEVEL% EQU 1 (
SET %ERRORLEVEL%=0
ECHO !TIME! - Host doesnt appear to be a HP Gen 8 or 9 server...skipping install >> !LOGFILE!
ECHO !TIME! - ExitCode !ERRORLEVEL! >> !LOGFILE!
IF DEFINED USERNAME (EXIT /B !ERRORLEVEL!) ELSE EXIT !ERRORLEVEL!
)
FOR /F "tokens=3" %%A IN ('wmic csproduct get name') DO (
if %%A equ Gen9 (
ECHO !TIME! - Installing software and drivers for HP Gen 9>> !LOGFILE!
ECHO !TIME! - Installing HP ProLiant Gen9 Chipset Identifier for Windows (cp021663)>> !LOGFILE!
"%~dp0source\cp021663a.exe" /s /f /LOG=!MSILOGFILE!
ECHO !TIME! - Installing Headless Server Registry Update for Windows (cp016819)>> !LOGFILE!
"%~dp0source\cp016819.exe" /s /f /LOG=!MSILOGFILE!
ECHO !TIME! - Installing PFA Server Registry Update for Windows (cp022305)>> !LOGFILE!
"%~dp0source\cp022305.exe" /s /f /LOG=!MSILOGFILE!
ECHO !TIME! - Installing HP ProLiant Integrated Management Log Viewer for Windows Server x64 Editions (cp022717)>> !LOGFILE!
"%~dp0source\cp022717.exe" /s /f /LOG=!MSILOGFILE!
)
if %%A equ Gen8 (
ECHO !TIME! - Installing software and drivers for HP Gen 8>> !LOGFILE!
ECHO !TIME! - Installing Headless Server Registry Update for Windows
(cp016819)>> !LOGFILE!
"%~dp0source\cp016819.exe" /s /f /LOG=!MSILOGFILE!
ECHO !TIME! - Installing PFA Server Registry Update for Windows
(cp022305)>> !LOGFILE!
"%~dp0source\cp022305.exe" /s /f /LOG=!MSILOGFILE!
ECHO !TIME! - Installing HP Broadcom Online Firmware Upgrade Utility for Windows Server x64 Editions (cp024029)>> !LOGFILE!
"%~dp0source\cp024029.exe" /s /f /LOG=!MSILOGFILE!
)
ELSE (ECHO !TIME! - ...model is not listed, so please add drivers >> !LOGFILE!)
The log file will show the following regardless if it is a gen 8 or gen 9 server: *note that its missing a ) at the end of the 2nd line after cp016819. Also note that it is not echoing the first line "Installing software and drivers for Gen 9"
Logfile
14:06:21.16 - Installing Headless Server Registry Update for Windows (cp016819
14:06:24.38 - Installing PFA Server Registry Update for Windows (cp022305)
14:06:27.47 - Installing HP ProLiant Integrated Management Log Viewer for Windows Server x64 Editions (cp022717)
So the problem is that the script only goes through Gen 9 if statement regardless if checks if it is a Gen 8 or 9. 2nd, it also skips the first few lines of the if statement (doesnt output to the log file as you can see above). I also know it is using Gen 9 because Gen 8 does not have the installer cp022717.
Any help will be much appreciated.
Thanks!