Adding custom tasks to BDD 2007 task sequences


In BDD 2007, we provide a task sequence that is preconfigured to do all of the activities needed to perform a deployment end-to-end (for Lite Touch, Zero Touch, refresh, upgrade, new computer, Windows XP, Windows Vista, etc.).  However, that doesn’t mean that it does everything you need.  Depending on your particular requirements, you may need to add your own custom steps to the task sequence.  That’s one of the benefits of having the task sequencer and task sequence editor available: you can make whatever adjustments you require.

Now, that doesn’t mean that making those adjustments is always a simple process.  For example, let’s assume you want to add batch files or simple Command Shell commands into the task sequence.  Some things to keep in mind to help assure that these run successfully:

  • Command lines that contain spaces need to be surrounded by quotes.  The parameters to those commands should not be included in the quotes (although some of them may also require quotes, depending on the command being executed).
  • Working directories should not have quotes.  The task sequencer will set the working directory via a Windows API (which doesn’t need quotes) before launching the command.
  • Avoid characters that look like XML, e.g. >, <, &, as these could cause XML parsing errors.
  • Batch files can’t have UNC path working directories.  CMD.EXE does not support this, so if you specify a working directory that is a UNC path, then execute CMD.EXE or a batch file that implicitly invokes CMD.EXE, the working directory will likely end up being set to C:\WINDOWS\SYSTEM32 – possibly harmless, depending on what your batch file does, but if the working directory is necessary to find the batch file, then there is a problem.
  • Know the difference between a command processed by CMD.EXE and an executable in its own right. Don’t specify CMD.EXE commands directly without using a batch file or a “CMD.EXE /C” prefix. A few examples:
    • NET.EXE can be used directly (with or without the .exe)
    • XCOPY.EXE can be used directly (with or without the .exe)
    • COPY must be used with “CMD.EXE /C”, e.g. “CMD.EXE /C COPY C:\BLAH C:\BLAH2”, or used in a batch file.
    • MD or MKDIR must be used with “CMD.EXE /C”, or used in a batch file.
    • Other examples of commands built into CMD.EXE:  CLS, DIR, COLOR, DATE, ECHO, ERASE, EXIT, FIND, LABEL, MOVE, PATH, RD, RMDIR, START, TYPE
    • Other examples of commands that are stand-alone executables: ROBOCOPY, XCACLS, FORMAT, DISKPART, TASKKILL, SC, GPUPDATE
  • Don’t specify a working directory of “.\anything” (e.g. “.\Applications”) in the task sequence because the current working directory is not guaranteed. (Notice that when you add an application from Workbench, which does use this “.\” notation, it translates “.\” into “%DEPLOYROOT%\”. This is done at deploy time by the ZTIApplications.wsf script.)
  • The task sequencer expects all actions to indicate whether they were successful via the exit code (return code).  By default, exit code 0 and 3010 (reboot required) are considered to be successful, and all other values are considered failures.  If you task returns something other than 0 or 3010, be sure to add those valid values to the list of successful return codes on the “Options” pane.  (You can also modify your batch file to include an “exit 0” statement to force a success return code, when appropriate.)

What if you want to test out a new task sequence action without running an entire deployment to do it?  Well, you can create your own stand-alone task sequencer XML file, then tell it to run that.  (Note that the typical environment variables, e.g. DEPLOYROOT or SCRIPTROOT, won’t be defined in this case.)  Here’s the process that you need for that:

  1. Create a TS.XML file that looks like the following, substituting your working directory value for the “startIn” value (e.g. “C:\BLAH”) and the command between the action tags (e.g. “TEST.CMD”).

    <?xml version=”1.0″ encoding=”utf-8″?>
    <sequence version=”2.00″ name=”SA Task Sequence” description=”SA Task Sequence”>
    <step name=”X” disable=”false” continueOnError=”false” description=”” startIn=”C:\BLAH” successCodeList=”0 3010″>
    <action>TEST.CMD</action>
    </step>
    </sequence>
  2. Save this file into “\Distribution\Tools\x86” (or x64, if you are running on an x64 OS).
  3. From command prompt (elevated, if you are running on Windows Vista or Windows Server “Longhorn”), execute this command with the working directory set to “C:\Distribution\Tools\x86”:

    start /wait tsmbootstrap.exe /env:SAStart
  4. Look at the return code before executing any more commands:

    echo %errorlevel%

    If the return code is 0, the task completed successfully. If the return code is non-zero but you didn’t see any error dialog, the TS.XML file is probably invalid. Otherwise, for all other errors the task sequencer should display an error dialog.
  5. Check the SMSTS.LOG file for additional information about the execution of the task. This will be located in %WINDIR%\SYSTEM32\CCM\LOGS\SMSTSLog if there is an SMS client installed on the machine. Otherwise, check the %TEMP% directory, or worst case, the C:\SMSTSLog directory if %TEMP% is not valid. This is a cumulative file, so start at the bottom and work your way up. (The TRACE32.EXE utility from the SMS 2003 Toolkit 2 download is useful for viewing this file.)
  6. Remove the TS.XML file from the \Distribution\Tools\x86 directory so it doesn’t get in the way of future deployments.

Any other suggestions?  If so, please submit comments below and I’ll continue to integrate them into this posting.


Comments (9)

  1. Anonymous says:

    True, the task sequencer does expect to find an ANSI TS.XML file, so don’t save it as UTF-8 or UTF-16.

    -Michael

  2. Anonymous says:

    Thanks…this helped me with some issues i had with Task Sequencing…

    Is there a way to test an application installation without running an entire deployment?

  3. Anonymous says:

    Very helpful – thanks for the post!

    -tfurst

  4. Anonymous says:

    I’m still having issues with batch files in the TS. For some reason my batch file will run when selected through the BDD wizard, but when it is a part of the TS it always fails. It also continues to work when I add it as a dependency to another application being run in the TS.

  5. Anonymous says:

    Hi Michael,

    We are seeing some very wierd behavior in the lab in regards to applications getting installed and sysprep.

    Syprep seems to be hanging until we move the mouse…and then continues to seal the OS. Samething with one of our apps…Presentation Director 2.57 and 2.55 from Lenovo.

    I spoke with our Microsoft Rep….and this seems to be a problem that is getting reported from his clients as well.

    Thanks

    -James

  6. Anonymous says:

    Can you please reword this.  I cannot get the custom task sequences to work.  

    ———————————————–Don’t specify a working directory of “.anything” (e.g. “.Applications”) in the task sequence because the current working directory is not guaranteed. (Notice that when you add an application from Workbench, which does use this “.” notation, it translates “.” into “%DEPLOYROOT%”. This is done at deploy time by the ZTIApplications.wsf script.)

    ———————————————–

    <![LOG[Expand a string: %DEPLOYROOT%ApplicationsTools_TEST]LOG]!><time="21:52:13.843+480" date="11-21-2007" component="TSManager" context="" type="0" thread="2124" file="executionenv.cxx:849">

    <![LOG[Start executing the command line: DeployTools_v11.CMD]LOG]!><time="21:52:13.843+480" date="11-21-2007" component="TSManager" context="" type="1" thread="2124" file="instruction.cxx:2815">

    <![LOG[!——————————————————————————————–!]LOG]!><time="21:52:13.843+480" date="11-21-2007" component="TSManager" context="" type="1" thread="2124" file="instruction.cxx:2844">

    <![LOG[Executing command line: "DeployTools_v11.CMD"]LOG]!><time="21:52:13.843+480" date="11-21-2007" component="TSManager" context="" type="1" thread="2124" file="commandline.cpp:763">

    <![LOG[Process completed with exit code 1]LOG]!><time="21:52:14.484+480" date="11-21-2007" component="TSManager" context="" type="1" thread="2124" file="commandline.cpp:1013">

    <![LOG[!——————————————————————————————–!]LOG]!><time="21:52:14.484+480" date="11-21-2007" component="TSManager" context="" type="1" thread="2124" file="instruction.cxx:2894">

    <![LOG[Failed to run the action: Tools_TEST.

    Incorrect function. (Error: 00000001; Source: Windows)]LOG]!><time="21:52:14.484+480" date="11-21-2007" component="TSManager" context="" type="3" thread="2124" file="instruction.cxx:2984">

    <![LOG[Sending status message . . .]LOG]!><time="21:52:14.484+480" date="11-21-2007" component="TSManager" context="" type="1" thread="2124" file="utility.cxx:296">

    <![LOG[Executing in non SMS standalone mode. Ignoring send a task execution status message request]LOG]!><time="21:52:14.484+480" date="11-21-2007" component="TSManager" context="" type="1" thread="2124" file="utility.cxx:305">

    <![LOG[Set a global environment variable _SMSTSLastActionRetCode=1]LOG]!><time="21:52:14.484+480" date="11-21-2007" component="TSManager" context="" type="0" thread="2124" file="executionenv.cxx:735">

    <![LOG[Set a global environment variable _SMSTSLastActionSucceeded=false]LOG]!><time="21:52:14.484+480" date="11-21-2007" component="TSManager" context="" type="0" thread="2124" file="executionenv.cxx:735">

    <![LOG[Clear local default environment]LOG]!><time="21:52:14.484+480" date="11-21-2007" component="TSManager" context="" type="0" thread="2124" file="executionenv.cxx:874">

    <![LOG[Let the parent group (CoreApplications) decides whether to continue execution]LOG]!><time="21:52:14.593+480" date="11-21-2007" component="TSManager" context="" type="0" thread="2124" file="instruction.cxx:3093">

    <![LOG[Let the parent group (State Restore) decide whether to continue execution]LOG]!><time="21:52:14.593+480" date="11-21-2007" component="TSManager" context="" type="0" thread="2124" file="instruction.cxx:2353">

    <![LOG[The execution of the group (State Restore) failed and the execution is aborted. An action fails.

    Operation aborted (Error: 80004004; Source: Windows)]LOG]!><time="21:52:14.609+480" date="11-21-2007" component="TSManager" context="" type="3" thread="2124" file="instruction.cxx:2316">

    <![LOG[Failed to run the last action: Tools_TEST. Execution of task sequence failed.

    Incorrect function. (Error: 00000001; Source: Windows)]LOG]!><time="21:52:14.609+480" date="11-21-2007" component="TSManager" context="" type="3" thread="2124" file="engine.cxx:199">

  7. Anonymous says:

    Michael!  Thanks for the steps above!  Very helpful!!

    Interestingly, the process fails if the TS.XML file is saved as UTF-8 (e.g. from Notepad)… must be saved as ANSI.  TS gives an error (illegal character on line 1, char 1) if it is saved as UTF-8.  Works if ANSI.  If you find out anything about this, please email me at danh at intelliem dot com.

  8. showbox says:

    Thanks for the great info. I really loved this. I would like to apprentice at the same time as you amend your web site, how could i subscribe for a blog site?
    For more info on showbox please refer below sites:
    http://showboxandroids.com/showbox-apk/
    http://showboxappandroid.com/
    Latest version of Showbox App download for all android smart phones and tablets.
    http://movieboxappdownloads.com/ – It’s just 2 MB file you can easily get it on your android device without much trouble. Showbox app was well designed application for android to watch movies and TV shows, Cartoons and many more such things on your smartphone.
    For showbox on iOS (iPhone/iPad), please read below articles:
    http://showboxappk.com/showbox-for-ipad-download/
    http://showboxappk.com/showbox-for-iphone/
    Showbox for PC articles:
    http://showboxandroids.com/showbox-for-pc/
    http://showboxappandroid.com/showbox-for-pc-download/
    http://showboxforpcs.com/
    There are countless for PC clients as it is essentially easy to understand, simple to introduce, gives continuous administration, effectively reasonable. it is accessible at completely free of expense i.e., there will be no establishment charges and after establishment
    it doesn’t charge cash for watching films and recordings. Not simply watching, it likewise offers alternative to download recordings and motion pictures. The accompanying are the strides that are to be taken after to introduce Showbox application on Android.
    The above all else thing to be done is, go to the Security Settings on your Android telephone, Scroll down and tap on ‘Obscure sources’.

  9. aw says:

    hai, I just want to tell you that I am just very new to blogs and seriously loved this website. More than likely I’m planning to bookmark your blog post .
    You amazingly come with really good posts. Thanks a lot for sharing your blog Microsoft.

    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Teknik
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Teknisi
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Televisi
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Teller
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20TNI
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Trans7
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20PLN
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Telkomsel
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Kimia%20Farma
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Jakarta%20Selatan
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Jakarta%20Pusat
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Jakarta%20Barat
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Jakarta%20Timur
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Jakarta%20Utara
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20Indosat
    http://www.lokerjobindo.com/search/label/Lowongan%20Kerja%20XL%20AXIATA
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Bangka%20Belitung
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Gorontalo
    http://www.lokerjobindo.com/search/label/Loker%20Daera%20Jambi
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Jawa%20Barat
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Jawa%20Tengah
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Jawa%20Timur
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Kalimantan%20Barat
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Kalimantan%20Selatan
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Kalimantan%20Tengah
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Kalimantan%20Timur
    http://www.lokerjobindo.com/search/label/Loker%20Daerah%20Kalimantan%20Utara