We use a customised Microsoft Deployment Toolkit (MDT) task sequence to build our desktop PCs so the script gets called as the last step in the "Gather Logs and StateStore on Failure" group:

The script is called as "Run Command Line" step running "cscript.exe "%deployroot%\scripts\UWEShowBuildError.wsf"

and will show the something like this if an error occurs during the task sequence:

The script will also create a small log file recording this error UWEShowBuildError.log which ends up with the rest of task sequence logs (System32\CCM\LogFiles)
Download the script here.
(I use the pre-fix "UWE" on our scripts, variables, etc to distinguish them from the Microsoft scripts)