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

40 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)

    Reply
  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.

    Reply
  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

    Reply
  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 ?

    Reply
  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

    Reply
  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

    Reply
  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

    Reply
  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

    Reply
  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.

    Reply
  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: 0x00000005
    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

    Reply
  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

    Reply
  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!

    Reply
  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(0x80070002)
    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=0x80070002. The operating system reported error 2147942402: The system cannot find the file specified.

    Reply
  14. 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.

    Reply
  15. 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

    Reply
  16. 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

    Reply
  17. Hi Peter,

    Just a suggestion that you might want to modify in your script.
    The USMT_WORKING_DIR should not be the same directory where you run scanstate and loadstate from. This directory tries to delete itself when scanstate or loadstate is completed.
    The result is you being unable to run loadstate because the files are no longer present.

    Cheers

    Reply
    • Hi Philip,
      The scripts mentioned in this post are working and tested, but I don’t have the updated scripts with me at the moment… Out of my head it’s just little changes, like setting USMT_WORKING_DIR to a temporary folder like %2\Temp, just make sure it’s an existing folder.
      Peter

      Reply
  18. Thanks for the response. Your suggestion worked out. I am not a programmer. So reading the others messages did not “click” until your response helped me out.

    Reply
  19. Hello
    The task sequence is working fine in FullOS version but i am having problems with the WinPE approach. My situation is a little different then normal, the Users folder (the one that contains the profiles directories for all the users in our windows 7 machines) is redirected to the D: drive, In FullOS the system recognizes that the logged on user that is starting the TS has the profile in D: drive and during the scanstate it starts creating the hardlink files in both drivers C: and D:, the system then goes to WinPE, applies the image on C: the do the loadstate and when the users log on again everything is ok, ne image applied and the old profiles with all the data is correctly assumed.
    The problem here is that in WinPE mode i noticed that during the scanstate the hardlinking folders are just created for drive C: and drive D: e completely ignored. This way the users profile isn’t saved and after the all process when the users logs on to the new OS a completely new profile without any old data is created.

    Any ideas on who can i force the TS to hardlink the profiles in drive d:? I assume that in FullOS mode it works fine because the system detects that the current logged on user has it own profile in drive D: so it captures that data, in offline mode it just looks in the default location, at least that is my understanding.

    Thank you for your help

    Reply
  20. any chance i can get a copy of your ts?

    i’m guessing you are hardcoding some of those variables – the architechture for example or are you detecting that somehow from within winpe?

    Reply
  21. a) Most of the times I just specify it, as I have seperate Task Sequences for x86 and x64. But you could for example set a condition based on the OS version.

    how can you do this? when i attempt such things whe i pxeboot – it never gets detected because it’s running in winpe and in ram. This stuff works well when going from full OS and doing zero touch, but can’t get it to work when you pxe boot. It’s as if the operating system and it’s c drive are a mystery to winpe.

    Reply
  22. Peter I’m getting ready to do a large deployment of XP to 7 upgrades which would include Bare metal, replace, refresh scenarios. Question pertains to the refresh and replace since that would require saving users existing data either through SMP’s or Hardlinks.
    I am in test phase in coming up with a golden task sequence, any suggestions or recommendations? Can I include both on a single task sequence.

    Ran into an issue in test, so on the XP system when i started the task sequence here is what happens:
    a. I have it set to restart the machine incase any locked files are running.
    b. After the reboot I log back in and the task sequence continues capturing data using hardlinks parameters just fine.
    c. After the OS get’s installed, SCCM client gets installed.
    d. I can see it’s doing the hardlink restore, however during or around this time I press f8 to determine no network connectivity, ipconfig nothing comes up. (This is a virtual environment).
    e. After OS gets installed I login locally I can see the Userstate folder and double clicking on the USMT.exe displays all my user. So at what point am i suppose to add the device drivers. I can’t seem to find NIC drivers for vmware workstation.

    Thanks.

    Reply
    • You need to apply the drivers before the Setup Windows and ConfigMgr step.

      VMware drivers are always challenging.. You need to do a good search in your sources, or your current machines to find the correct drivers.

      Reply

Leave a Reply to Peter van der Woude Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.