In task sequence how to pass variable value to script
Hi, I have defined a computer variable, %NewComputer%, for a system. And i have a task sequence to create a folder on %NewComputer%, USMT. This step works fine. The problem is i now want to run a script and set share permissions on the %NewComputer%\USMT folder. In the script i am using strComputer = "%NewComputer%", but the system running the TS is not recognizing %NewComputer% in the script. I seen a post about about passing the variable in the TS step. So I have tried running cscript.exe myscript.vbs "%NewComputer% but it still fails. The error is unable to communicate with the computer "%NewComputer% I am not sure what is wrong here, and how to pass the value of %NewComputer% to the script? Any suggestions?
April 25th, 2012 11:04am

made some progress. I If for argument sake %NewComputer% = Windows7 If i my TS i run: cscript.exe "%deployroot%\scripts\myscript.vbs %NewComputer%" the TS fails but in the smsts.log it errors with Input Error: There is no script engine for file extension ".vbs Windows7". I have tried moving quotes around but that's not helping. I am sure i'm close, anyone have any suggestions?
Free Windows Admin Tool Kit Click here and download it now
April 25th, 2012 12:20pm

Hi, it should work if you use: cscript.exe "%deployroot%\scripts\myscript.vbs" %NewComputer% If not try without quotes at all that should also work. regards, Jrgen -- My System Center blog ccmexec.com -- Twitter @ccmexec
April 25th, 2012 12:48pm

Thanks, in both cases, with or without quotes, it exits with: The remote server machine does not exist or is unavailable: 'GetObject'. If you look in the event log in both cases DCOM was unable to communicate with the computer %NewComputer% using any of the configured protocols. is logged.
Free Windows Admin Tool Kit Click here and download it now
April 25th, 2012 2:54pm

what about.... cscript.exe "%deployroot%\scripts\myscript.vbs" %%NewComputer%% Step by Step ConfigMgr 2007 Guides | Step by Step ConfigMgr 2012 Guides | I'm on Twitter > ncbrady
April 25th, 2012 4:49pm

What Jorgen put above is correct and should work. Have you verified that NewCOmputer is being properly set by dumping the variables before the script is run? Is the task running the script a run command-line task using alternate credentials? If so, then the task sequence environment is not the same and the variables are not properly available.Jason | http://blog.configmgrftw.com | Twitter @JasonSandys
Free Windows Admin Tool Kit Click here and download it now
April 25th, 2012 7:52pm

How do you provide the %newcomputer% variable in your script? I think your script not automatically knows all TS variables. Either you use wscript.arguments or you can use the sms.ts.environment object regards, Stefan
April 27th, 2012 5:54am

I do appreciate all the help, thankyou very much. I am fairly certain the NewComputer variable is being set as their are steps prior in the TS that use that variable to create folders on NewComputer. And although some steps are being run with alternate credientials, this step that is failing is not. Besides, depending on how i run the script it will fail recognizing the NewComputer value, Input Error: There is no script engine for file extension ".vbs Windows7". It knows Windows7 is the value. The script is setup like this: strComputer = "%NewComputer%" Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objNewShare = objWMIService.Get("Win32_Share") Then i my run command-line task sequence step, but regardless of how i setup that cmd line, it fails. I've tried every combination.
Free Windows Admin Tool Kit Click here and download it now
April 27th, 2012 8:18am

Hi, Does this script work when you run it manually? The argument in the vbscript should be collected from the wscript.arguments, i doubt that the vbscript enginge can handle the %newcomputer% variable as it is not defined in the vbscript. This should work though: Set objArgs = WScript.Arguments strComputer = WScript.Arguments(0) Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objNewShare = objWMIService.Get("Win32_Share") Otherwise you must use the sms.ts.environment object as Jabby pointed out. regards, Jrgen-- My System Center blog ccmexec.com -- Twitter @ccmexec
April 27th, 2012 8:53am

Hi bud dy, you write you use strComputer = "%NewComputer%" The script will take %NewComputer% as a string if you use the two quotation marks. But this is only another problem if you still get the error message that you have the wrong file extension try it with the sms environment. start your script with the commandline cscript.exe "%deployroot%\scripts\myscript.vbs" in your script add following lines set objEnv =CreateObject("Microsoft.SMS.TSEnvironment") strComputer = objEnv("NewComputer") regards, Stefan
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2012 9:15am

Thank you both Jabby and Jorgen. Clearly i don't script all that much. Trial and error with your suggestions, and adding to the script this: strComputer = WScript.Arguments(0) and running the script like this worked: cscript.exe "%deployroot%\scripts\myscript.vbs" %NewComputer% Many thanks again
May 1st, 2012 7:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics