It turns out that errorlevel is returning the exit code of iterating statement in the for loop instead of the one immediately preceding it.
for /r \\computer\share\x86 %%x in (*.xml) do (
IsVarMap.exe /file:"%%x"
echo %ERRORLEVEL%
)
Echoes 0 always. I expect some iterations to return 2, when xml file isn’t a VarMap.
IsVarMap.exe /file:notavarmap.xml
Echoes 2 as expected