Using TS variables when running a script under a different account.

One of the features available when running a Task Sequence in Config Mgr R2, is to run a command line as a different user, which can comes in handy in a number of scenarios. There is however a small but important thing to be aware of.

When using this step to run a script, you will notice that you cannot use any of the “task sequence variables”, as they are not passed through to script. So if you need to use any of the TS variables in your scripts you will have to pass them to the script as arguments instead.

1: Add the argument feature to your script

Set ArgObj = WScript.Arguments

2: Set your variables based one the argument added to the script

strObjectOU = ArgObj(0)

strDomain = ArgObj(1)

It is now possible to use the values stored in the Task Sequence Variables OU and DOMAIN by running the script like this:

Cscript.exe script.vbs %OU% %DOMAIN%

%OU% will be passed through as argument 0 setting the script variable strObjecteOU to the value stored in %OU%. %DOMAIN% will be passed on as argument 1 and so forth.

The is no limit to how many arguments can be passed through, but be aware that one argument must be one complete line ex. %DOMAIN% =

Should the variable be composed of more lines ex. %OU% = OU=Clients,OU=Domain Computers,DC=MyDomain,DC=com you will have to put it in quotations or the %OU% argument would actually be two arguments OU=Clients,OU=Domain and Computers,DC=MyDomain,DC=com

About the Author:

Michael Petersen
Twitter: @OSDeployLinkedin: Michael PetersenMicrosoft Community Contributor


  1. acai berry diet exposed cnn December 15, 2013 at 15:13 - Reply

    Ecellent post. I definitely appreciate tyis site.
    Stick with it!

    Check out my blog post … acai berry diet exposed cnn

  2. sid June 20, 2014 at 0:51 - Reply


    I am going to use this in MDT to move the computers from staging OU to Computers OU.
    I tried to make sense of what you wrote here, but I could not understand it..
    could be more specific or give some example?

  3. lotto strategies July 22, 2014 at 4:12 - Reply

    You really makee it seem really easy along with your presentation however I
    in finding this topic to be really one thing that I frel I might never understand.
    It seems too complicated and very large for me. I’m taking a ook ahead for youur next submit, I’ll try to get the cling of it!

    Here is my site; lotto strategies

Leave A Comment