WMIC not returning the right errorlevel
Posted: 13 Sep 2012 21:23
Here's a simple script that reads a list.txt file for KB patches and queries local machine using WMIC to see if its installed
@echo on
setlocal enabledelayedexpansion
for /f %%i in (list.txt) do (
wmic qfe get hotfixid |findstr /i "%%i"
if %errorlevel% equ 0 @echo %%i found
)
I am always getting %errorlevel% 0 .. why?
Here's sample output
C:\Temp>(
wmic qfe get hotfixid | findstr /i "KB961371"
if 0 EQU 1
)
C:\Temp>(
wmic qfe get hotfixid | findstr /i "KB2584146"
if 0 EQU 1
)
KB2584146
C:\Temp>(
wmic qfe get hotfixid | findstr /i "KB2585542"
if 0 EQU 1
)
KB2585542
The second and third time it should be zero and it is but the first time it doesn't find the patch but still returns zero.
Thanks in advance for help!
@echo on
setlocal enabledelayedexpansion
for /f %%i in (list.txt) do (
wmic qfe get hotfixid |findstr /i "%%i"
if %errorlevel% equ 0 @echo %%i found
)
I am always getting %errorlevel% 0 .. why?
Here's sample output
C:\Temp>(
wmic qfe get hotfixid | findstr /i "KB961371"
if 0 EQU 1
)
C:\Temp>(
wmic qfe get hotfixid | findstr /i "KB2584146"
if 0 EQU 1
)
KB2584146
C:\Temp>(
wmic qfe get hotfixid | findstr /i "KB2585542"
if 0 EQU 1
)
KB2585542
The second and third time it should be zero and it is but the first time it doesn't find the patch but still returns zero.
Thanks in advance for help!