Capture User Files and Settings Offline (WinPE) or Online (FullOS) with ConfigMgr 2007

They always say never change a winning team, but sometimes its just cowl to see if its possible to be even better. I had the same with a previous post in which I already showed how to do a Hard-Link migration, when started from WinPE (and FullOS). The biggest part of that example is still the same, but some pieces changed to get a better result.

In this post I will go step-by-step (again) to mention the changes that I made to make it even better. At the end of both parts of this post I will shine a light on the changes that I made.

Part 1: Capture User Files and Settings

HardlinkOnOffTSFor creating a Task Sequence, that does an Online or Offline Capture, my way, a few variables and locations need to be created. After that a command line has to be run to do the actual Capture. Under here I will sum up the steps I take to do an Online and Offline Capture (also see the first red rectangle in the picture):

  • Set Started in WinPE – Set Task Sequence Variable
    This step sets the Task Sequence Variable TSStartedInWinPE to YES. This Task Sequence Variable only gets set when _SMSTSInWinPE is TRUE.
  • Set Architecture – Set Task Sequence Variable
    This step sets the Task Sequence Variable Architecture to amd64. This variable will be used for selecting the USMT 4.0 version for (in my case) 64-bit systems.
  • Set Windows Partition – Set Task Sequence Variable
    This step sets the Task Sequence Variable WindowsPartition to C:. This variable will be used for selecting the Windows partition.
  • Set State Store Location – Set Task Sequence Variable
    This step sets the Task Sequence Variable OSDStateStorePath to %WindowsPartition%\StateStore. This variable will be used for creating and selecting the User State Location.
  • Create State Store Location – Run Command Line
    This step creates the directory %WindowsPartition%\StateStore by running the Command line: cmd /c MKDIR %OSDStateStorePath%.
  • Cache USMT Files and Scripts – Run Command Line
    This step caches the USMT Files and Scripts from the USMT Package to the directory %OSDStateStorePath%\USMTFiles\ by running the Command line: xcopy * %OSDStateStorePath%\USMTFiles\ /herciy
  • Capture User Files and Settings – WinPE – Run Command Line
    This step does the actual Offline Capture of the User Files and Settings by running the Command line RunScanState_WinPE.BAT %OSDStateStorePath% %WindowsPartition% %Architecture% %_SMSTSLogPath% which has to start in the directory %OSDStateStorePath%\USMTFiles\. This step only runs when the machine is started from WinPE. This is done by checking if the Task Sequence Variable TSStartedInWinPE is set to YES.
  • Capture User Files and Settings – FullOS – Run Command Line
    This step does the actual Online Capture of the User Files and Settings by running the Command line RunScanState_FullOS.BAT %OSDStateStorePath% %WindowsPartition% %Architecture% %_SMSTSLogPath% which has to start in the directory %OSDStateStorePath%\USMTFiles\. This step only runs when the machine is started from FullOS. This is done by checking if the Task Sequence Variable TSStartedInWinPE is not set to YES. 

These are all the steps I need, to do an Online or Offline Capture with Hard-Links. Now let’s take a closer look at the batch-files which do the most of the work:

RunScanState_FullOS.BAT

REM ======================================================
REM ARGUMENT -1- OSDStateStorePath     = %1
REM ARGUMENT -2- WindowsPartition    = %2
REM ARGUMENT -3- Architecture        = %3
REM ARGUMENT -4- LogDirectory        = %4
REM ======================================================

SET USMT_WORKING_DIR=%1\USMTFiles\%3

REM ======================================================
REM RUN Scanstate
REM ======================================================

"%1\USMTFiles\%3\Scanstate.exe" "%1" /o /hardlink /nocompress /i:%1\USMTFiles\%3\MigUser.xml /i:%1\USMTFiles\%3\MigApp.xml /localonly /l:%4\ScanState.log /v:5 /progress:%4\ScanStateProgress.log /c /efs:hardlink

REM ======================================================
REM EXIT Errorlevel
REM ======================================================

EXIT /b %errorlevel%

RunScanState_WinPE.BAT

REM ======================================================
REM ARGUMENT -1- OSDStateStorePath     = %1
REM ARGUMENT -2- WindowsPartition    = %2
REM ARGUMENT -3- Architecture        = %3
REM ARGUMENT -4- LogDirectory        = %4
REM ======================================================

SET USMT_WORKING_DIR=%1\USMTFiles\%3

REM ======================================================
REM RUN Scanstate
REM ======================================================

"%1\USMTFiles\%3\Scanstate.exe" "%1" /o /hardlink /nocompress /i:%1\USMTFiles\%3\MigUser.xml /i:%1\USMTFiles\%3\MigApp.xml /offlinewindir:%2\Windows /localonly /l:%4\Scanstate.log /v:5 /progress:%4\Scanstateprogress.log /c /efs:hardlink

REM ======================================================
REM EXIT Errorlevel
REM ======================================================

EXIT /b %errorlevel%

The changes that I made in Part 1: Capture User Files and Settings are the following two:

  1. I use now a batch-file for both, and Online and Offline Capture.
    Why? Just because it gives me more flexibility and because I can get rid of a few “double” steps. For example, now I can use the same Store Location (variable) for both Captures Types.
  2. I use now a different location for the logfiles.
    Why? Just because it gives me an easy possibility to save the log until the end of the Task Sequence.

Part 2: Restore User Files and Settings

After the User Files and Settings have been captured, they need to be restored again to the new OS. This is the same for an Online and Offline Capture. Under here I will sum up the steps that I use to restore the Files and Settings:

  • Restore User Files and Settings – Run Command Line
    This step does the actual Restore of the User Files and Settings by running the Command line RunLoadState.BAT %OSDStateStorePath% %WindowsPartition% %Architecture% %_SMSTSLogPath% which has to start in the directory %OSDStateStorePath%\USMTFiles\..
  • Cleanup State Store Location – Run Command Line 
    This step cleans up the State Store Location by running the command line RunUSMTutils.BAT %OSDStateStorePath% %Architecture%
  • Restart in FullOS – Restart Computer (see the second red rectangle in the picture)
    This step will restart the computer, but only when _SMSTSLastActionRetCode is equal to 2.

These are all the steps I need, to do a Restore with Hard-Links. Now let’s take a look at the batch-files which do most of the work here:

RunLoadState.BAT

REM ======================================================
REM ARGUMENT -1- OSDStateStorePath     = %1
REM ARGUMENT -2- WindowsPartition    = %2
REM ARGUMENT -3- Architecture        = %3
REM ARGUMENT -4- LogDirectory        = %4
REM ======================================================

SET USMT_WORKING_DIR=%1\USMTFiles\%3

REM ======================================================
REM RUN LoadState
REM ======================================================

"%1\USMTFiles\%3\Loadstate.exe" "%1" /hardlink /nocompress /lac /i:%1\USMTFiles\%3\MigUser.xml /i:%1\USMTFiles\%3\MigApp.xml /l:%4\LoadState.log /v:5 /progress:%4\LoadStateProgress.log /c

REM ======================================================
REM EXIT Errorlevel
REM ======================================================

EXIT /b %errorlevel%

RunUSMTutils.BAT

REM ====================================================== 
REM VARIABLE -1- OSDStateStorePath = %1
REM VARIABLE -2- Architecture = %2
REM ======================================================

REM ======================================================
REM RUN USMTUtils
REM ======================================================

echo y| "%~dp0%2\usmtutils.exe" /rd "%1"

REM ======================================================
REM EXIT Errorlevel
REM ======================================================

EXIT /b %errorlevel%

The changes that I made in Part 2: Restore User Files and Settings are the following two:

  1. I use now also batch-file for the Restore.
    Why? Just because it gives me more flexibility and because I can get rid of a “double” step (setting the Hardlink options).
  2. I use now an optional restart of the computer.
    Why? Because I noticed that sometimes USMTUtils ends with code 2, which means that it needs a restart to get rid of the last files.

Note: The RunScanState_FullOS.BAT, RunScanState_WinPE.BAT, RunLoadState.BATand the RunUSMTutils.BAT have to be placed inside the USMT Package at the same level as the amd64- and the x86-folder.

More information about the Scanstate Syntax:
http://technet.microsoft.com/en-us/library/dd560781(WS.10).aspx
More information about the LoadState Syntax:
http://technet.microsoft.com/en-us/library/dd560804(WS.10).aspx
More information about the USMTUtils Syntax: http://technet.microsoft.com/en-us/library/dd560799(WS.10).aspx

Share

27 thoughts on “Capture User Files and Settings Offline (WinPE) or Online (FullOS) with ConfigMgr 2007

  1. This is written for moving pc from xp to win7, correct?
    Can this also be used for a side by side to move from xp to xp? (assuming I use USMT 3 instead of 4)

  2. Correct and it can also be used to do a refresh from W7 to W7.

    It can not be used to do a refresh from WXP to WXP, because the loadstate of USMT 4.0 is not made for WXP. USMT 3.0 is not an alternative, because it does not support Hard-Links and/ or Offline Mode.

  3. Hi Peter
    Thanks for sharing your experience online, it’s great learning material for someone who (like me) is still trying to learn the basics. A few of questions about your task sequence:
    a) Do you specify the architecture or do you calculate it , if you do calculate then how ?
    b)when you do your xcopy how do you just get the package contents and not everything on the share ?
    c) Do you have any advice on how, or when you need to edit the migapp.xml or miguser.xml files
    d) what are the actions behind the tasks in the error logging sequence ?
    thanks

  4. I’m pretty sure I’ve followed your example precisely , but I’m having some problems with the restore phase. Looking in the c:\statestore\usmtfiles\x86 directory after the machine has completed the full task list I can see that most of the files in the USMT package that were all copied (I checked) over in the earlier xcopy , have been deleted including loadstate.exe , all that is left is scanstate and a few dll’s – any idea what the problem might be ?

  5. Hi Peter
    I’ve looked at the link above and that doesn’t seem to be it, firstly I’m using SP2 and it is not the saved state that is being deleted it is the loadstate.exe and its associated files.
    If I put a pause at the bottom of the RunScanSate_WinPE.BAT I can stop the TS in it’s tracks to examine what’s on disk prior to the image being applied. Using F8 I can examine the contents of the c:\statestore\usmtfiles\x86 dir after teh package is cached and before the RunScanState_WinPE.BAT file runs and that has all the files in the package ( 24 files, 4 dirs) after the scanstate.exe has run most of the x86 dir have been deleted except scanstate.exe and 7 dll’s ( like migcore.dll , migstore.dll etc ) the contents of c:\statestore\usmtfiles\amd64 and the batch files in c:\statestore\usmtfiles\ are unaffected and the stored data in c:\statestore\usmt is also present and correct. Unsurprisingly the Loadstate section of the TS then goes on to fail since none of it’s required files exist by the time it runs.

    Also I’m not sure there is a commandline switch of efs:hardlink so I’ve swapped that for efs:skip

  6. Hi Doug,
    I indeed saw this behaviour before… At this moment I don’t know what causes it, but I do know some workarounds.
    Workaround 1: Create another [b]Cache USMT Files and Scripts [/b]-step to copy the files again.
    Workaround 2: In the [b]Restore User Files and Settings [/b]-step select the USMT 4.0 Package and delete the Start in location.
    Peter

    PS: The commandline switch efs:hardlink does exist. Take a look here for the Scanstate syntax: http://technet.microsoft.com/en-us/library/dd560781(WS.10).aspx

  7. Hi Peter
    yeah I gone with the first option , copying the files again before the restore ( and again prior to the usmtutils call ) annoying but there it is.
    Also I’ve had to create a task to copy the DlManifests folder to the %OSDStateStorePath%\USMTFiles directory , since that is my working directory when running the scanstate , otherwise the scanstate logs would show an error because the "Download Manifest folder is not present" , this task is inserted just before the capture usmt tasks. Thanks

  8. Hello Peter,

    I am attempting to use your above instructions to hardlink and refresh an OS outside of SCCM using only MDT 2010. My problem is I cannot see what the other steps are actually calling script/instruction wise for the remainder of the steps. If you could give me a little insight I’m sure I can find a way to make this work without having to install SCCM wish is a very unlikely solution for me. Thanks for any help.

    Alex

  9. Hi Alex,

    First of, I am sorry for my late response…
    Second, I assume that this should also be very good useable with MDT. Because the [b]Capture [/b]and [b]Restore [/b]parts that I use are all Run Command Line -steps (kicking off bat-files) and actually nothing is builtin from ConfigMgr.

  10. Hi Peter,

    I have to deploy around 1500 workstations and laptops, all of them have Windows XP SP3 right now, with a single partition, all the computers have been used for quite a while, so I have to migrate the user State also.

    The problem is that I can¥t use hardlink migration because I have to repartition the harddrive in order to acomodate the 200mb system partition for BitLocker. I used the scripts recomended by you, and adapted them to capture de user state in the local harddrive and copie them to remote location on the SCCM server. After the backup is moved to the server, the computer restart in WinPE and should format the hard-drive, but the process stops and gives the following error:

    !——————————————————————————————–!
    Expand a string: WinPE
    Executing command line: osddiskpart.exe
    ==============================[ OSDDiskPart.exe ]==============================
    Command line: "osddiskpart.exe"
    Succeeded loading resource DLL ‘X:\sms\bin\i386\1033\TSRES.DLL’
    Reading partition size info for partition 0
    Remaining size before partition: 80023749120
    size units: SIZE_MB
    Set partition size: 104857600 OSDDiskPart
    Remaining size after partition 0: 79918891520
    Reading partition size info for partition 1
    Remaining size before partition: 79918891520
    size units: SIZE_PERCENT
    100% size specified.
    Remaining size after partition 1: 0
    Disk 0 contains protected path "C:\StateStore"
    FALSE, HRESULT=00000005 (e:\nts_sms_fre\sms\client\osdeployment\osddiskpart\main.cpp,1421)
    Attempt to partition disk containing a protected path. Disk index = 0
    OSDDiskPart.exe failed: 0×00000005
    Process completed with exit code 5
    !——————————————————————————————–!
    Failed to run the action: Format and Partition Disk.
    Access is denied. (Error: 00000005; Source: Windows)

    Basically, the process does not format and repartiotion de hardrive because I has a protected path, in this case C:\StateStore, where I am storing the .MIG file generated by USMT 4. I even tried deleting the folder after the content have been moved to the server.

    The USMT BAT file that I am using, extracted from your website and modified is:

    REM =====================================================
    REM ARGUMENT -1- OSDStateStorePath = %1
    REM ARGUMENT -2- WindowsPartition = %2
    REM ARGUMENT -3- Architecture = %3
    REM ARGUMENT -4- LogDirectory = %4
    REM ======================================================
    SET USMT_WORKING_DIR=%1\USMTFiles\%3
    REM ======================================================
    REM RUN Scanstate
    REM ======================================================
    "%1\USMTFiles\%3\Scanstate.exe" "%1" /o /i:%1\USMTFiles\%3\MigUser.xml /i:%1\USMTFiles\%3\MigApp.xml /localonly /l:%4\ScanState.log /v:5 /c /vsc /efs:copyraw /all
    REM ======================================================
    REM EXIT Errorlevel
    REM ======================================================
    EXIT /b %errorlevel%

    Thanks for your help, I don¥t know if I am simply doing everything wrong at this point!!!!

    http://dl.dropbox.com/u/1492072/TaskSequence.png

  11. Hi Peter,

    Thanks for your quick reply, to answer you questions, I am not usyng the built in steps because I´m in Venezuela and there is an issue with GMT-04:30 and USMT, and I have no control over the ScanState.exe command line, so I rather use your scripts.

    In social technet Mark Thomas recomended me to use hardlink, and then create the system partition for bitlocker with BdeHdCfg.exe -target default -quiet. I definetly think that this is the way to go. I am still going to use your scripts for hardlink, and the after restoring the user state, I´ll create the system partition.

    If everything goes right Ill send you the info so you can post it in you blog, as I think it is very helpfull.

    Regards,

    Carlos Vollbracht

  12. Hi Peter,

    Thank you for explaining the hard-linking steps.

    However at the "Cache USMT Files and Scripts" step all my packages are being copied to the local hard drive.
    I read the question above saying: When you do your xcopy how do you just get the package contents and not everything on the share ?
    But after selecting the USMT 4.0 Package in the Properties it still keeps copying all packages.

    Do you have any idea?

    Thanks a lot in advance!

  13. Peter,

    I found the sollution to my previous problem to be in moving the USMT package from the local C:\Program files\WAIK\Tools directory to my Distr share.

    The Capture User Files and Settings gives me an error code…..
    Working on this now, but haven’t found the solluction yet.

    Error:
    The task sequence execution engine failed executing the action (Capture User Files and Settings) in the group (Capture User Files and Settings) with the error code 2147942402
    Action output: 1′
    Command line for extension .BAT is "%1" %*
    Set command line: Run command line
    Working dir ‘C:\StateStore\USMTFiles\’
    Executing command line: Run command line
    CreateProcess( NULL, (LPWSTR)m_sCommandLine.c_str(), NULL, NULL, TRUE, bNT ? CREATE_UNICODE_ENVIRONMENT : 0, m_pEnvironmentBlock, pszWorkingDir, &si, &pi ), HRESULT=80070002 (e:\nts_sms_fre\sms\framework\core\ccmcore\commandline.cpp,997)
    clCommandLine.Execute( uOptions, pszWorkingDir, lpDesktop ), HRESULT=80070002 (e:\nts_sms_fre\sms\client\osdeployment\installsoftware\runcommandline.cpp,558)
    cmd.Execute(pszPkgID, sProgramName, dwCmdLineExitCode), HRESULT=80070002 (e:\nts_sms_fre\sms\client\osdeployment\installsoftware\main.cpp,385)
    CreateProcess failed. Code(0×80070002)
    Command line execution failed (80070002)
    Failed to execute command line ‘RunScanState_FullOS.BAT C:\StateStore C: x86 C:\Windows\system32\CCM\Logs\SMSTSLog’ .
    Unknown error (Error: 80070002; Source: Unknown)
    Install Software failed to run command line, hr=0×80070002. The operating system reported error 2147942402: The system cannot find the file specified.

  14. Most times it has something to do with settings of the Advertisement. Make sure [b]Access content directly from a Distribution Point when needed by the running Task Sequence [/b]is not selected.

  15. Hi Peter, i keep having the problem of task sequence error during the “capture user files and settings” error code is 0×80070002. kindly help ASAP.

    Regards.

  16. Hi Peter,
    I believe that I have followed this as to the letter, but there seems to be a problem in the caching of the USMT files. The files that are copied are not the ones that are in the c:\program files\windows aik\tools\usmt folder. This is where my package for the User State Migration Tool is located.

    Have I put the batch files in the wrong location?

    Thanks

  17. Hi Peter,
    Thanks for the response. Where is the package referenced in the task sequence. Nowhere can I see that the package is actually imported or is this something that SCCM just knows?
    Ian

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>