With the following ComObjects you can easily read/ write and create task sequence variables.
To use TS variables in a powershell script use the following lines of code;
To initialize the ComObject while in TS:
1 |
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment |
To display a TS variable value use:
1 |
$tsenv.Value("OSDComputerName") |
To write a value to a TS variable use :
1 |
$tsenv.Value("OSDComputerName") = "PC_MyComputerName" |

Source information was found from here.