in reply to Passing value from IF loop

Did you check inside your script or after the script was run on the command line?

When you set environment variables, they only get inherited by sub-processes of the process that is setting them. At least that is how it works in unix and I assume also in windows.