SCCM - How to read & write custom vars using PowerShell in a task sequence

I’ve been looking for a method of reading and writing custom variables from within a task sequence as I will shortly be writing a Powershell GUI front-end for our imaging task and being able to do this step is an essential pre-requisite to achieving my end goal.

I used three Microsoft articles in my research on how to do this:

  1. About Task Sequence Variables
  2. Task Sequence Built-In Variables
  3. Prestart commands for task sequence media

I thought I would try a ‘real-world’ example – something that may have some real value in the workplace – while I tried to figure out how all of this worked. I decided to use the tried and tested “Hello World!” SCCM equivalent of logging the following information into the computers registry once imaging was complete :

  • Date image started
  • Image Start time
  • Image End Time
  • Total time taken to image
  • Task sequence used to image
  • Name of image used

Here is a screenshot of the final result taken from the registry of an imaged computer:
1-1

Part 2 explains how I went about achieving this.