Persisting ConfigMgr Packages during a Task Sequence
The MDT Task Sequences for System Center Configuration Manager 2007 use a clever technique to download and persist the MDT Files package during each phase of the Task Sequence. The Use Toolkit Package step uses the ZTISCCM.wsf script to copy the contents of the package to a WDPackage subfolder of the _SMSTaskSequence folder. The Task Sequencer maintains this folder (the path of which is held in the _SMSTSMDataPath variable) for holding the logs and downloaded package contents. So the WDPackage folder will continue to exist until the next reboot. MDT places the path to the WDPackage folder in the DeployRoot variable.
Doing this prevents repeated download of the MDT Files every time the execution of an MDT script is needed. My customer wanted to be able to used the same technique for their custom scripts. They maintain a package of custom scripts so that they are not mixed in with the MDT scripts. This will allow them to update/replace the MDT Files package as needed without having to worry about their custom scripts.
One way of doing this would be to simply create a Run Command Line step (after the Use Toolkit Package step) that simply does an xcopy of the files/folder in the package to either DeployRoot or ScriptRoot or a subfolder of those paths. You can then call your scripts relative to the DeployRoot or ScriptRoot variable.
I wanted to provide my customer with maximum flexibility for this so I created a custom script called ZTI-PersistSccmPackage.wsf. This script should be copied to the root of the package along with a copy of the MDT script ZTIUtility.vbs. The command has the following syntax:
cscript ZTI-PersistSccmPackage.wsf /pathvar:<path variable name> /xcopy:"<additional xcopy switches>"
The /pathvar switch sets the name of the variable the can be used to reference the path to the persisted files. If you specify a variable name that is either DeployRoot, ScriptRoot, or ToolRoot, the script will copy the contents of the package to the corresponding location in the WDPackage folder created by the Use Toolkit Package step. If you specify any other variable name, the script will create a randomly named folder in the _SMSTSMDataPath location, copy the contents of the package to that folder, and set a Task Sequence variable pointing to that folder path with the variable name specified with the /pathvar switch. For example, if you had a package of custom scripts you wanted to persist in their own folder, you would could run the script like this:
cscript ZTI-PersistSccmPackage.wsf /pathvar:CustomScriptRoot
You could then reference your scripts using the CustomScriptRoot variable. For example, if the package contained a script called MyScript.wsf you could run it from a Run Command Line step using the following syntax without having to add the package to the step:
cscript "%CustomScriptRoot%\MyScript.wsf"
The optional /xcopy switch is used to specify additional switches for the xcopy command. By default, the script uses xcopy with the following switches: /s /e /h /y /c. For example, if you wanted to add the /d switch to filter the copy by date or add the /exclude switch to exclude files from the copy, you would specify those using the /xcopy switch.
Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use .
This post was contributed by Michael Murgolo, a Senior Consultant with Microsoft Services - U.S. East Region.
Comments
- Anonymous
July 16, 2010
Way cool, dude!!