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
For 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:
- 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.
- 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:
- 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).
- 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