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% = MyDomain.com.
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