It’s possible to write a task sequence variable but not the Windows Environment Variables. But you can write a simple wsf file and use the in-built registry write function.
<job id=” Z_Filename.wsf “>
<script language=”VBScript” src=”ZTIUtility.vbs”/>
oShell.RegWrite “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\MDTPath”, oEnvironment.Item(“DeployRoot”), “REG_SZ”
oLogging.CreateEntry “Registry Value Successful.”, LogTypeInfo
Save the file Z_Filename.wsf to scripts folder
From the task sequence, just create a step run command cscript.exe “%SCRIPTROOT%\Z_Filename.wsf”
Above script creates an system variable called MDTPath and set the value to the oEnvironment.Item(“DeployRoot”) which would be \\servername\sharename$ in this case.