none
Task Sequence variable set by powershell not surviving reboot & retry RRS feed

  • Question

  • Hi everyone,

    I'm having some problems setting tasksequence variables in PowerShell. After a reboot the variable is gone. I'm using this approach in a Powershell script during deployment. E.G.:

    $TSenv:CustomVariable = 'Some Value'

    The variable is now usable throughout the script. However, I make use of the SMSTSRebootRequested and SMSTSRetryRequested variables to reboot and retry the script depending on some conditions and after the reboot the variable is either gone or has no value. I check for the existence of the variable at the beginning of the script, like so:

    If ($TSEnv:CustomVariable) { <Run second run script> } else { <Run first run script>

    If ($RebootRequired)
    {
    $TSEnv:CustomVariable = 'Some Value'

    $TSenv:SMSTSRebootRequested = $true $TSenv:SMSTSRetryRequested = $true return "Continue after reboot."
    } }


    Can anyone explain why this doesn't work? I have MDT 2013 U1 and I'm not using SCCM.

    Friday, January 22, 2016 12:38 PM

All replies

  • Define the custom variable in customsettings.ini 

    [Settings]

    Priority=Default

    Properties=CustomVariable

    Oh and get update 2. It isn't related to this issue but, is a better product.


    Logs are very important. https://keithga.wordpress.com/2014/10/24/video-mdt-2013-log-files-basics-bdd-log-and-smsts-log/ Mention any customizations you have made.


    Monday, January 25, 2016 5:30 AM
    Moderator
  • Define the custom variable in customsettings.ini 

    [Settings]

    Priority=Default

    Properties=CustomVariable

    I forgot to mention this, but I already have that in my INI file, but it's not working.

    To test this I have the following line at the beginning of my script:

    Write-Host "Custom Variable is now: '$TSEnv:CustomVariable'"
    After a reboot the log should contain:
    Custom Variable is now: 'Some Value'

    But this is what's actually in the log:

    Custom Variable is now: ''


    Monday, January 25, 2016 12:30 PM
  • It just got weirder. I've just added a second step to my task sequence with the same script. When that second step reboots and retries it shows the value of the previous step!! I suspect that when a retry is requested all TS variables that were set by the script get discarded. The variable only becomes permanent if the script ends without a retry. I'm guessing it's by design, but if anyone knows a way around this I would appreciate it. Right now I work around this issue by writing the value to a text file which I read after a retry, but I don't like this approach.
    • Edited by MicaH_Z Thursday, January 28, 2016 8:34 AM
    Thursday, January 28, 2016 8:33 AM