SCCM Client Site Code
Hi Hoping someone will have a quick answer for this! We have a central site server & a number of primaries - all of our OSD config (Images, TS's, Col's & Adverts) is on the central, and we are still deploying XP. New builds & rebuilds need to be done at several AD sites, and frequently not on the site where the finalised machine will end up. The build & process has been ported from SMS 2003 OSD. Brief overview of build process...1. PXE boot using pre-execution hook.2. Pre-execution scripts determine if authorised, machine name & TS required from third party database & then use Maik Koster's webservice to add the machine to the required collection.3. TS then executed & machine built Obviously as all the OSD is on the central site, this is where the machine ends up following the Setup Windows & ConfigMgr TS step. What I would like to do is be able to change the SMSSITECODE parameter using a script before the client setup is run. In this way the client would end up assigned to the correct SCCM site regardless of where it is physically built. (note I can determine the site required from machine name, and appreciate I will have to either script or manually remove the temporary machine that will have been created on the central during the build process). I've thought I'd be able to make a number of conditional Setup Windows & ConfigMgr TS steps, with the SMSSITECODE installation parameter specified on each one depending on the condition. It seems the SMSSITECODE parameter is not permitted as an Installation Option of this step. I'm assuming that the step makes use of the _SMSTSSiteCode built in task sequence variable. Could someone explain if this is actually how it works & if the variable could be changed during the TS before the config manager client is installed. Many thanks
March 26th, 2010 5:31am

you can set that variable using 1E's Tsenv2 tool Advanced Task Sequence Environment Tool The TSEnv2.exe is a command line tool that lets administrators manipulate the Microsoft 2007 task sequence environment. It allows them to get, set, list and dump all variables within the OSD Task Sequence environment. This tool also allows changes to ‘read only’ variables that cannot be changed with the original TSEnv.exe which is included in the Configuration Manager 2007 OSD environment. boot up into winpe to test it, get the variables, review the values for Site code, you can script it quite easily to change the site code... hth please share your results when done, cheers niall My step by step SCCM Guides windows-noob on Twitter
Free Windows Admin Tool Kit Click here and download it now
March 26th, 2010 8:17am

Hi i've the same problem, i've downloaded the tool but when i launch it with the list parameter the following 2 errors appear. Where i have to put the file? Error: OpenFileMapping('Global\{51A016B6-F0DE-4752-B97C-54E6F386A912}') failed: 2 ReadEnvironmentBlockFromNamedSection failed: 0x80070002. Thanks
March 29th, 2010 3:37am

are you trying this in winPE ? if you create a boot image in ConfigMgr by choosing Create MDT boot image (you'll need to integrate mdt...) My step by step SCCM Guides windows-noob on Twitter
Free Windows Admin Tool Kit Click here and download it now
March 29th, 2010 4:07am

Yes just tried with winpe the same error occurred.
March 29th, 2010 9:59am

How have you planned to target the machines? What criteria do you use to decide which site a computer will belong to? Or do you want to have a manual option during deployment?
Free Windows Admin Tool Kit Click here and download it now
March 29th, 2010 10:09am

Thanks Niall It's exaclty what I needed! I have played with this today & done the following to automatically set the site code & machine name during the TS... Brief overview of NEW build process...1. PXE boot using pre-execution hook.2. Pre-execution scripts determine if authorised, machine name & TS required from third party database & then use Maik Koster's webservice to add the machine to the required collection.3. TS then executed & machine built (All the same up to here but TS modified as follows)3a. Just after the Apply Operating System task in the TS I have created a new task to run a command. This executes a script I've written which determines the Machine Name from the ZTIgather in step 2 which is already in a custom environment variable. From this name I can determine the site I wish the computer to belong to (just some simple logic around the machine name specific to our naming convention). Finally the script calls tsenv2.exe to set the _SMSTSSiteCode & _SMSTSMachineName TS variables. 3b. Following this two great things happen: Firstly, during the Apply Windows Settings task the correct machine name makes it into sysprep.inf. And secondly, when the Setup Windows & ConfigMgr task runs the SCCM client is installed with the site code I want. Also the tool has been invaluable for troubleshooting the whole process as I can see how & more importantly when the environment variables are changing. It's a MUST HAVE for anyone doing OSD via SCCM! Note my boot image was created using Create Boot Image using Microsoft deployment (2010) in SCCM console & has all the ZTI scripts etc included as add files (some of these from Maik Koster's kit for the Webservice - which is great by the way!). Also includes the tsenv2 tool now. ------------------- Zolabus - The error you're getting might be that the SCCM deployment environment isn't loaded at the time you're wanting to use the tool. I have found that you need to be in the TS ( & in WinPE) to get any results. For example if I PXE boot to my WinPE boot image & hit F8 for a command prompt I can use the tool right up to the point that the TS initiates a reboot for mini setup. At this point I've still got my command prompt open but the tool stops functioning with the error you describe - presumably because the TS has gracefully unloaded the environment at this point. Another thought is that the environment might not be there yet. This will depend if your using a preexecution hook that sets it up - if not just start the TS & then check the tool as this should set the env up ready.My advice would be to add some MsgBox's to any of your TS or pre-execution hook scripts temporarily as this will pause the deployment process & give you chance to use tsenv2 to check things out. Cheers Douks
March 29th, 2010 1:02pm

glad to hear its working now :) cheers niall My step by step SCCM Guides windows-noob on Twitter
Free Windows Admin Tool Kit Click here and download it now
March 29th, 2010 1:07pm

Niall Your quick response and knowledge of the existence & working of the 1e tool has saved me quite literally hours (if not days!) of research into how this SCCM OSD stuff works under the covers. It's also clear evidence that the technet forums are without doubt THE BEST internet community resource for those working with MS products. Thanks once again Douks
March 29th, 2010 3:52pm

Douks, thanks for your response. Can you post your script to change the sitecode? If i understand correctly i have to execute the TS and after the Apply Operating System task insert a command task executing the script
Free Windows Admin Tool Kit Click here and download it now
March 30th, 2010 4:04am

Yes, straight after the Apply OS task is where I call it. Here are the bare bones of the script (ZTISetNameAndSite.wsf) as requested. Once you've customised as required, call the script with wscript in the task sequence (Oh, & make sure the standard ZTI scripts & TSENV2.EXE are available in the same location)... <job id="ZTISetNameAndSite"> <script language="VBScript" src="ZTIUtility.vbs" /> <script language="VBScript" src="ZTIDataAccess.vbs" /> <script language="VBScript"> ' //*************************************************************************** ' // ***** Script Header ***** ' // ' // File: ZTISetNameAndSite.wsf ' // ' // Purpose: Called by SCCM Deployment Task Sequence to set Name & Site Code. ' // ' // Usage: wscript.exe ZTISetNameAndSite.wsf [/debug:true] ' // ' // Customer Script Version: 1 ' // ' // ' // Customer History: 1 - Initial Coding By Douks ' // ' // ***** End Header ***** ' //*************************************************************************** Option Explicit RunNewInstance '//---------------------------------------------------------------------------- '// '// Global constant and variable declarations '// '//---------------------------------------------------------------------------- ' No global constants needed '//---------------------------------------------------------------------------- '// Main Class '//---------------------------------------------------------------------------- Class ZTISetNameAndSite '//---------------------------------------------------------------------------- '// Class instance variable declarations '//---------------------------------------------------------------------------- Dim iRetVal '//---------------------------------------------------------------------------- '// Constructor to initialize needed global objects '//---------------------------------------------------------------------------- Private Sub Class_Initialize End Sub '//---------------------------------------------------------------------------- '// Main routine '//---------------------------------------------------------------------------- Function Main Dim iRetVal Dim sCmd Dim iCount Dim sNewName Dim sNewSite ' Initialization iRetVal = Success '//---------------------------------------------------------------------------- '// Get Name & Site Code '//---------------------------------------------------------------------------- ' Make use of standard environment access from MDT utility sNewName = oEnvironment.Item("ThisIsMyCustomEnvVariableThatsAlreadySet") ' Determine site from name ' This is where I determine the name & site required & will need coding for your specific environment ' Aim is to return sNewName & sNewSite to pass to the next bit... '//---------------------------------------------------------------------------- '// Set Name & Site Code '//---------------------------------------------------------------------------- 'Make use of 1e TSENV2.EXE tool to set read only TS variables accordingly sCmd = "x:\deploy\scripts\tsenv2.exe set _SMSTSMachineName" & "=s" & sNewName iRetVal = RunAndLog(sCmd, true) sCmd = "x:\deploy\scripts\tsenv2.exe set _SMSTSSiteCode" & "=s" & sNewSite iRetVal = RunAndLog(sCmd, true) End Function 'Execute and log a command 'Taken from Original MDT 2010 source files Function RunAndLog(sCmd, bDebuggable) Dim iRetVal Dim iShow If oLogging.Debug and bDebuggable then sCmd = sCmd & " /debug:true" iShow = 1 Else iShow = 0 End if oLogging.CreateEntry "About to run command: " & sCmd, LogTypeInfo On Error Resume Next iRetVal = oShell.Run(sCmd, iShow, true) If Err then iRetVal = Err.Number oLogging.CreateEntry "ERROR executing command " & sCmd & ": " & Err.Description & " (" & Err.Number & ")", LogTypeError ElseIf iRetVal = -2147021886 or iRetVal = 0 then oLogging.CreateEntry "Successfully executed command " & sCmd & ", rc = " & CStr(iRetVal), LogTypeInfo Else TestAndLog iRetVal, "ZTISetNameAndSite: Non-zero return code executing command " & sCmd & ", rc = " & iRetVal End if RunAndLog = iRetVal On Error Goto 0 End Function End Class </script> </job>
March 30th, 2010 5:21am

Hi zolabus, As this thread is considered answers by the others, I'm just wondering if the script I posted was of any help & how you're getting on with it now? Cheers
Free Windows Admin Tool Kit Click here and download it now
April 2nd, 2010 12:32pm

It doesn't seem this tool is available anymore for download on 1E's site. Does anyone know if there is an updated version of TSEnv2.exe that works with 2012 RTM? I have tried using the old version and it doesn't work.Levi Stevens Technical Consultant - End User Computing - West Region Dell | Services
September 21st, 2012 6:05am

Levi, I downloaded the file earlier this week. I did have to register in order to get access to it however. I don't know the answer to whether or not it works with 2012.
Free Windows Admin Tool Kit Click here and download it now
September 27th, 2012 10:37am

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

Other recent topics Other recent topics