Excellent post by Michael Murgolo on how to set Environment Variables in a Task Sequence.
Some tools require setting an environment variable when they are used. For example, the User State Migration Tool has several that can be used for troubleshooting. One is discussed in the Ask the Directory Services Team blog post here. Unfortunately, the built-in MDT or ConfigMgr Task Sequence steps for capturing and restoring the user state don’t allow you to set environment variables.
More details refer to above link ………….