I have written a script which Stops/starts the application pool in IIS server, everything is working fine but I am unable to get few statements logged in nested If I have used in the script, Below is script code
set CUR_YYYY=%date:~10,4%
set CUR_MM=%date:~4,2%
set CUR_DD=%date:~7,2%
set LOG_FILE=C:\TEMP\StopStartPool_%CUR_YYYY%%CUR_MM%%CUR_DD%.log
echo Stopping App Pool: %date% %time% >> %LOG_FILE%
cd %windir%\system32\inetsrv
appcmd stop apppool /apppool.name:TestMER1
IF %ERRORLEVEL% NEQ 0 (
echo Error Occurred while stopping pool - %ERRORLEVEL%: %date% %time% >> %LOG_FILE%
echo Rerunning Stop Command: %date% %time% >> %LOG_FILE%
TIMEOUT /T 30
cd %windir%\system32\inetsrv
appcmd stop apppool /apppool.name:TestMER
IF %ERRORLEVEL% EQU 0 ( echo Application pool has stopped on rerun >> %LOG_FILE% )
)else ( echo Application pool has stopped: %date% %time% >> %LOG_FILE% )
TIMEOUT /T 60
echo Starting App Pool: %date% %time% >> %LOG_FILE%
cd %windir%\system32\inetsrv
appcmd start apppool /apppool.name:TestMER1
IF %ERRORLEVEL% NEQ 0 (
echo Error Occurred while starting pool - %ERRORLEVEL%: %date% %time% >> %LOG_FILE%
echo Rerunning Start Command: %date% %time% >> %LOG_FILE%
TIMEOUT /T 30
cd %windir%\system32\inetsrv
appcmd start apppool /apppool.name:TestMER
IF %ERRORLEVEL% EQU 0 ( echo Application pool has Started on rerun >> %LOG_FILE% )
)else ( echo Application pool has Started: %date% %time% >> %LOG_FILE% )
echo -----------------Finished--------------------- >> %LOG_FILE%
Here is a log I am getting in a file,
Stopping App Pool: Tue 04/30/2019 3:18:38.61
Error Occurred while stopping pool - 1168: Tue 04/30/2019 3:18:38.81
Rerunning Stop Command: Tue 04/30/2019 3:18:38.81
Starting App Pool: Tue 04/30/2019 3:20:08.13
Error Occurred while starting pool - 1168: Tue 04/30/2019 3:20:08.41
Rerunning Start Command: Tue 04/30/2019 3:20:08.41
Script is working as expected it just that It is not logging below code result
IF %ERRORLEVEL% EQU 0 ( echo Application pool has stopped on rerun >> %LOG_FILE% )