Painless Profile Migration
Migrate profiles without leaving your chair
October 8, 2006
I recently had to upgrade more than 1500 desktop PCs running Windows 2000 and different Microsoft Office versions to Windows XP and Office 2003. I had to destroy the current file system instead of upgrading it from the previous OS for several reasons, including incompatibility problems between the old and new versions of some of the company's internal software. I needed a way to back up all the users' profiles on the PCs, then restore the profiles after installing the new XP and Office 2003 software.
When you have 1500 PCs, physically going to every PC to perform the upgrade is too time-consuming. I decided to back up the profiles on a network share, then restore the profiles from that share onto the PCs so that I could perform all the work remotely. I first looked for existing solutions. I discovered that XP offers the Files and Settings Transfer Wizard, which lets you back up user profiles, store them on a network share, and restore them when needed. (For information about how to use the wizard, see the Microsoft article "Step-by-Step Guide to Migrating Files and Settings" at http://www.microsoft.com/technet/prodtechnol/winxppro/deploy/mgrtfset.mspx.) Although you can use this wizard on Win2K machines, it has some disadvantages. The wizard can backup only the profile of the currently logged on user. Consequently, you can't backup all the profiles that reside on one computer in one operation. More important, you have to run the wizard locally. Because I needed to migrate the profiles on remote machines, using the wizard wasn't an option.
I then discovered the User State Migration Tool (USMT). This Microsoft tool lets you easily migrate all user profiles and has a lot of options to offer, including the ability to migrate application settings and to use the tool in a script. However, USMT compresses the backup file, which means it takes a long time to back up and restore profiles, especially when users have large profiles that take up a couple of gigabytes. In my case, running this tool, even at night, wasn't a option because many users in the company work at night.
When I searched the Windows Scripting SolutionsWeb site for profile migration tools, I found a solution that Rick Early provided in the article "Copying Win2K PC Profiles" (October 2002, InstantDoc ID 26356). His solution lets you quickly migrate user profiles. However, it's written for PC-to-PC migrations. I needed a solution that would let me migrate profiles from a PC to a network share then back to the PC.
Because none of the existing solutions I found was ideal, I decided to adapt Rick Early's solution. My ProfileBackup solution executes in two phases: backup and restore. The backup phase involves running one main script (SavePC.bat) and three supporting scripts (SaveProfile.bat, Del-TempFiles.vbs, and SavePC.kix). The restore phase involves running one main script (CopyPC.bat) and two supporting scripts (RestoreRegistry-Profile.bat and CopyPC.kix).
The Backup Phase
In the backup phase, ProfileBackup performs a variety of tasks. It first checks the remote computer for profiles that weren't used by anyone in a defined period of time. If any old profiles exist, the solution deletes them to ensure that only the necessary profiles are migrated. Deleting old profiles helps keep network traffic to a minimum during the backup and restore operations. After deleting the old profiles, ProfileBackup copies the files it needs to perform several tasks on the remote computer. ProfileBackup then performs those tasks, which consist of deleting each profile's temporary files, backing up relevant profile registry keys, and copying all the profiles into a folder on the network share.
Now that you know the tasks that ProfileBackup performs in the backup phase, let's take a look at how it achieves them. The solution starts with the launching of SavePC.bat, which Listing 1 shows. This script uses the Microsoft Windows Server 2000 Resource Kit's User Profile Deletion utility (Delprof.exe). You can use Delprof .exe to delete user profiles on local or remote PCs. You use the utility's /d: parameter to specify the maximum number of days a user profile can remain inactive. As callout A in Listing 1 shows, in this case, Delprof.exe will delete profiles that have been inactive for more than 62 days. You can change this parameter to any number you think will work best in your environment.
As callout B in Listing 1 shows, SavePC.bat uses the BackupFolder variable to store the Universal Naming Convention (UNC) path to the network-share folder in which you want to back up your user profiles. When customizing this variable's value, make sure that you don't include unnecessary spaces before or after the UNC path because the command processor considers these spaces part of the variable's value. (The variable's value can contain as many spaces as needed.) To run SavePC.bat, you must have change permissions (NTFS/ Share) for the network share on which the backup folder resides.
The two lines of code after callout B determine the location of the Windows folder on the remote PC. This check is necessary to execute Sysinternals' PsExec (http://www.sysinternals.com/utilities/psexec.html), a free utility that lets you run programs on a remote PC from your local computer. By default, this utility runs from the remote PC's local Windows directory (e.g., C:winntsystem32).
After obtaining the location of the local Windows directory, SavePC.bat copies several files to that directory, including the files needed to run KiXtart (.kix) scripts and SavePC.bat's three supporting scripts: SaveProfile.bat, DelTempFiles.vbs, and SavePC.kix. The code at callout C uses PsExec to run SaveProfile.bat, which first executes DelTempFiles.vbs. Del-TempFiles.vbs deletes each profile's temporary files as well as some folders that house those files. SaveProfile.bat then executes SavePC.kix, SavePC.kix backs up the relevant profile registry keys and saves the information in a file named ProfileList.reg.
After the supporting scripts run, SavePC.bat backs up the remote PC's profiles and the profile settings. As the code at callout D in Listing 1 shows, SavePC.bat uses the Microsoft Windows Server 2000 Resource Kit's Robocopy utility to copy the profiles from the remote PC's C:Documents and Settings folder to the backup folder specified by the BackupFolder variable. You can't use the built-in Xcopy command because it can't copy file and folder permissions. When you copy profiles, you must include the security settings for every file and folder. Unlike Xcopy, Robocopy copies files' and folders' security settings. As the code at callout E in Listing 1 shows, SavePC.bat uses the built-in Copy command to copy the registry's profile settings in the C:ProfileList.reg file to the backup folder.
When SavePC.bat ends, your backup folder will contain all the profiles (and their permissions) for that remote PC. After you've finished installing the new desktop software, you can restore those profiles.
The Restore Phase
In the restore phase, the Profile-Backup solution first deletes any default profiles that might have been installed when you installed the new OS on the remote PC (such as the ASPNET, AllUsers, and Administrator profiles), then copies the backed up profiles. The deletion of default profiles is necessary to prevent collisions between the current profile registry settings and the backed up registry settings.
Although I restored the profiles on the same PC from which I copied them, you can also restore the profiles on another PC. In that case, you need to rename the backup folder on the network share, giving it the name of the remote computer to which you want to restore the profiles. Whether you're restoring the profiles on the same PC or another PC, that PC's user can't be logged on during the restoration-process. Listing 2 shows CopyPC .bat, the main script in the restore phase. The script begins by warning you that it will eliminate all the profiles on the specified remote PC, then asks you to press any key to acknowledge that you want to do so. I added this feature to eliminate the risk of restoring the profiles on the wrong PC.
After setting the BackupFolder variable's value to the backup folder's UNC path (see callout A in Listing 2) and determining the location of the Windows folder, CopyPC.bat uses Delprof.exe to delete any default profiles that might have been installed when you installed the new OS. Then, as callout B in Listing 2 shows, the script uses Robocopy to copy the profiles data from the backup folder to the remote PC's C:Documents and Settings folder.
As callout C in Listing 2 shows, CopyPC.bat copies to the remote PC's Windows folder all the files it needs to restore the registry settings. Those files include RestoreRegistryProfile.bat, CopyPC.kix, and ProfileList.reg. CopyPC.bat uses PsExec to run RestoreRegistryProfile.bat. RestoreRegistryProfile.bat executes CopyPC.kix, which uses ProfileList.reg to write the necessary profile settings to the registry.
Running the Solution
You can find the ProfileBackup solution (ProfileBackup.zip) on the Windows Scripting Solutions Web site. (See page 1 for download information.) After you download ProfileBackup.zip, extract all the files. The files will automatically be placed in two folders—Backup and Restore—which will be in a folder named ProfileBackup.
Backing up the profiles on a remote computer is a simple two-step process:
Open SavePC.bat (Listing 1) in a text editor such as Notepad. In the code at callout B, customize the BackupFolder variable's value. Make sure that your UNC path doesn't include unnecessary spaces before or after the UNC path. If desired, customize the /d: parameter's value (i.e., the maximum number of days a user profile can remain inactive before getting deleted) in the code at callout A. You don't have to change any other script settings.
Open cmd.exe and navigate to the ProfileBackup solution's Backup folder. Type SavePC.bat followed by the name of the remote PC that contains the profiles you want to back up. For example, if you unzipped Profile-Backup on your E drive and you want to back up a computer named COMPUTER_OF_SIMON, the command would look like
E:ProfileBackupBackup> SavePC.bat COMPUTER_OF_SIMON
(Although this command appears on several lines here, you would enter it on one line in the command-shell window. The same holds true for the other multiline command in this article.)
Restoring profiles is also a two-step process:
Open CopyPC.bat (Listing 2) in a text editor. Customize the Backup-Folder variable's value in the code at callout A. This is the only setting you need to customize in any of the restore scripts.
Open cmd.exe and navigate to the ProfileBackup solution's Restore folder. Type CopyPC.bat followed by the name of the remote PC that contains the profiles you want to backup. For example, to restore the profiles on COMPUTER_OF_SIMON, the command would look like
E:ProfileBackupRestore> CopyPC.bat COMPUTER_OF_SIMON
When you use the ProfileBackup solution, keep in mind the following:
To back up the profiles on a remote PC, you must be an administrator for that PC.
Administrative shares (e.g., C$, D$, ADMIN$) must be enabled on the remote PC.
The scripts assume that the remote PC's profile path is the default C:Documents and Settings. If they're stored in another location, you can still use the solution if you customize the paths in SavePC.bat, DelTempFiles.vbs, and CopyPC.bat.
A profile shouldn't be in use when you're backing up and restoring profiles on the remote PC. Note that even though a computer might be at the logon prompt, a user's profile can still be in use by the OS. I recommend that you reboot the remote PC before starting the backup and restore operations, then leave the computer showing the logon prompt.
Like USMT, the ProfileBackup solution copies printer mappings, application shortcuts, and Outlook settings, but it doesn't copy printer drivers, applications, and Outlook .pst and .ost files that aren't stored in the user's profile folder. So, you must reinstall printer drivers and applications. You must also back up any .pst and .ost files outside profile's folder separately. Alternatively, you can move any misplaced .pst and .ost files to the profile folder on the remote PC before using the ProfileBackup solution. For example, if user named Simon has a .pst file stored in C:mypst.pst, you can move that file to Simon's profile folder (or a subfolder), such as C:Documents and SettingsSimonmypst.pst.
A Time-Saving Solution
I used the ProfileBackup solution to successfully migrate the profiles on all 1500 PCs. I found that it works much faster than any Microsoft-provided tools. More important, you can run the solution remotely, so you don't have to physically visit each PC.
About the Author
You May Also Like