• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1286
  • Last Modified:

Script User Favorites to a New Profile

Can anyone help me with a script.

I'm migrating users and computer accounts and the only thing I want to migrate from a Users profile to their newly created profiles is their "Favorites"

WIndows XP Users moving to new Profile in WIndows XP
WIndows 7 Users moving to new profile in WIndows 7

Is there a vbs script or batch file that anyone knows how to do this?

Thank you.
0
shoris
Asked:
shoris
  • 3
  • 3
1 Solution
 
RobSampsonCommented:
Do you want to copy the "Favorites" folder to a network location first, or are you copying straight from computerA to computerB?

Regards,

Rob.
0
 
ThinkPaperCommented:
This is if you plan on copying from the workstation to the server: (which is probably better than moving it from wkstn to wkstn.)

I used a logon script, which copied the favorites from their local box to the network.
After running for a week or 2, I check the LOG file to ensure that everythign is moved over successfully. Once I confirmed that users's favorites moved over successfully, I then redirected their Favorites via GPO.

'MigrateFavorites.vbs
'=====================================================================================================
'PRE:  Users MUST have read/write/create access to their PROFILE folder on SERVER
'      Users MUST have read/write/modify access to the LOGFILE itself and the folder it is located.
'      Script is attached as a LOGON USER script via Grouppolicy which creates the folder under the current USER'S account
'POST: Copy favorites from local machine to users' Favorite folder located in their profile folder.
'      AFTERWARDS - ADM template will redirect the path of saved favorites (THIS IS HANDLED AFTER MIGRATION IS COMPLETE)
'=====================================================================================================
'Date: 12.8.2011 Updated 1.17.2012

WScript.Sleep 10000

Dim objNetwork
Dim WShell
Dim logFile

logFile = "\\SERVER\FLDREDIR\_FavoriteLog\logFav.csv"		'CREATE & SET PATH TO LOG RESULTS ON SHARE


'ForAppending=8, ForReading=1, ForWriting=2
Const ForAppending=8

'On Error Resume Next

Set objNetwork = CreateObject ("WScript.Network")
Set WShell = CreateObject ("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUser = "NULL"

'===== Open Log File =====
Set WriteStuff = objFSO.OpenTextFile(logFile, ForAppending, True)

'===== Get Username =====
strUser = objNetwork.Username

localFavorites= "%USERPROFILE%" & "\Favorites"		'SET LOCAL FAVORITES PATH
profileFavorites = "\\SERVER\FLDREDIR\"& strUser & "\Favorites"	'SET PROFILE FAVORITES PATH

If Err.Number <>0 Then	'Error getting Username
	WriteStuff.WriteLine("NULL," & Err.Number & ", Error Retrieving Username, " & Date())

Else										'Else OK TO GO!


	'=====	PROFILE FAVORITES DO NOT EXIST, SO CREATE FOLDER =====
	If NOT objFSO.FolderExists(profileFavorites) Then

		objFSO.CreateFolder profileFavorites		
	End If
		
	If Err.Number <> 0 Then
		'============ LOG ERROR ================
		WriteStuff.WriteLine(strUser & "," & Err.Number & ", Error - Creating Profile Favorites folder, " & Date())	
	Else	

		'====== OTHERWISE PROFILE FAVORITES EXIST, SO MOVE FAVORITES =======
		Set f = objFSO.GetFolder(profileFavorites)


		objFSO.CopyFolder localFavorites & "\*", profileFavorites
		  If Err.Number <> 0 Then
			WriteStuff.WriteLine(strUser & "," & Err.Number & ", Error - Copying Favorites from Local, " & Date())
		  Else
			  		  
		 	objFSO.CopyFile localFavorites & "\*", profileFavorites & "\"

			  If Err.Number <> 0 Then
				WriteStuff.WriteLine(strUser & "," & Err.Number & ", Error - Copying Favorites from Local, " & Date())
			  Else
				WriteStuff.WriteLine(strUser & "," & Err.Number & ", Success - Copying Favorites from Local, " & Date())
				Err.Clear
			  End If
		  End If
						
	End If

End If

WriteStuff.Close
Set WriteStuff = NOTHING
Set objFSO = NOTHING
WScript.Quit

Open in new window

0
 
shorisAuthor Commented:
That's a great script, however, I want to copy the profile to the server then re-copy it back to the workstation.

Reason: I am migrating computer accounts to another domain and we are not using the ADMT tool to migrate the profiles. We are creating a new profile and with the new profile all we want to do is copy the favorites over.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RobSampsonCommented:
Hi, you could try this script to copy favorites from all user folders from the current computer to the server share.  It will save the favorites from each user to the path you speciy, plus the computer name and username.

For example, if you specify:
strDestination = "\\server\share\FavoritesBackup"

it will copy favorites for each user to
\\server\share\FavoritesBackup\<computername>\<username>\Favorites

strDestination = "\\server\share\FavoritesBackup"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
If Right(strDestination, 1) = "\" Then strDestination = Left(strDestination, Len(strDestination) - 1)
If objFSO.FolderExists("C:\Users") = True Then
	For Each objFolder In objFSO.GetFolder("C:\Users").SubFolders
		CopyFolder objFolder.Path & "\Favorites", strDestination
	Next
ElseIf objFSO.FolderExists("C:\Documents and Settings") = True Then
	For Each objFolder In objFSO.GetFolder("C:\Documents and Settings").SubFolders
		CopyFolder objFolder.Path & "\Favorites", strDestination
	Next
End If

Sub CopyFolder(strSource, strTarget)
	strFavorites = strSource & "\Favorites"
	If objFSO.FolderExists(strFavorites) = True Then
		If objFSO.FolderExists(strTarget & "\" & objNetwork.ComputerName) = False Then objFSO.CreateFolder strTarget & "\" & objNetwork.ComputerName
		If objFSO.FolderExists(strTarget & "\" & objNetwork.ComputerName & "\" & Mid(strSource, InStrRev(strSource, "\") + 1)) = False Then objFSO.CreateFolder strTarget & "\" & objNetwork.ComputerName & "\" & Mid(strSource, InStrRev(strSource, "\") + 1)
		objFSO.CopyFolder strFavorites, strTarget & "\" & objNetwork.ComputerName & "\" & Mid(strSource, InStrRev(strSource, "\") + 1) & "\"
	End If
End Sub

Open in new window


If you're happy with that, I can provide a script to restore those favorites, but you would need to manually type in the computer name that was the old computer of that user, and it would them back.

Alternatively, if your users only really use one computer, then we could take out the computer name altogether, and have the script run just for the currently logged on user, so you could back them up with one script for the current user, then restore them with another script for the current user.

Regards,

Rob.
0
 
shorisAuthor Commented:
that would be awesome if you can provide a script to restore please.
0
 
RobSampsonCommented:
Hi, sorry, the backup script was missing a little bit of code.  This should backup:
strDestination = "\\D5PYX82SRING\C$\Temp\Scripts\FavoritesBackup"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
If Right(strDestination, 1) = "\" Then strDestination = Left(strDestination, Len(strDestination) - 1)
If objFSO.FolderExists("C:\Users") = True Then
	For Each objFolder In objFSO.GetFolder("C:\Users").SubFolders
		'WScript.Echo "Copyping " & objFolder.Path & "\Favorites to " & strDestination
		CopyFolder objFolder.Path, strDestination
	Next
ElseIf objFSO.FolderExists("C:\Documents and Settings") = True Then
	For Each objFolder In objFSO.GetFolder("C:\Documents and Settings").SubFolders
		'WScript.Echo "Copyping " & objFolder.Path & "\Favorites to " & strDestination
		CopyFolder objFolder.Path, strDestination
	Next
End If

Sub CopyFolder(strSource, strTarget)
	strFavorites = strSource & "\Favorites"
	If objFSO.FolderExists(strFavorites) = True Then
		If objFSO.FolderExists(strTarget & "\" & objNetwork.ComputerName) = False Then objFSO.CreateFolder strTarget & "\" & objNetwork.ComputerName
		If objFSO.FolderExists(strTarget & "\" & objNetwork.ComputerName & "\" & Mid(strSource, InStrRev(strSource, "\") + 1)) = False Then objFSO.CreateFolder strTarget & "\" & objNetwork.ComputerName & "\" & Mid(strSource, InStrRev(strSource, "\") + 1)
		WScript.Echo "Copying " & strFavorites & " to " & strTarget & "\" & objNetwork.ComputerName & "\" & Mid(strSource, InStrRev(strSource, "\") + 1) & "\"
		On Error Resume Next
		objFSO.CopyFolder strFavorites, strTarget & "\" & objNetwork.ComputerName & "\" & Mid(strSource, InStrRev(strSource, "\") + 1) & "\"
		If Err.Number <> 0 Then
			WScript.Echo "Error " & Err.Number & ": " & Err.Description
		End If
		Err.Clear
		On Error GoTo 0
	End If
End Sub

Open in new window


and this should restore:
strSource = "\\D5PYX82SRING\C$\Temp\Scripts\FavoritesBackup"
If Right(strSource, 1) = "\" Then strSource = Left(strSource, Len(strSource) - 1)
strSource = InputBox("Please enter the source computer folder to restore favorites from:", "Source Folder", strSource & "\<COMPUTERNAME>")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
If objFSO.FolderExists(strSource) = True Then
	If objFSO.FolderExists("C:\Users") = True Then
		For Each objFolder In objFSO.GetFolder(strSource).SubFolders
			'WScript.Echo "Copyping " & objFolder.Path & "\Favorites to " & strDestination
			CopyFolder objFolder.Path, "C:\Users"
		Next
	ElseIf objFSO.FolderExists("C:\Documents and Settings") = True Then
		For Each objFolder In objFSO.GetFolder(strSource).SubFolders
			'WScript.Echo "Copyping " & objFolder.Path & "\Favorites to " & strDestination
			CopyFolder objFolder.Path, "C:\Documents and Settings"
		Next
	End If
Else
	WScript.Echo "Cannot find source folder " & strSource
End If

Sub CopyFolder(strSource, strTarget)
	strFavorites = strSource & "\Favorites"
	strRestoreTo = strTarget & "\" & Mid(strSource, InStrRev(strSource, "\") + 1) & "\Favorites"
	If objFSO.FolderExists(strFavorites) = True Then
		If objFSO.FolderExists(strRestoreTo) = True Then
			WScript.Echo "Copying " & strFavorites & " to " & strRestoreTo
			On Error Resume Next
			objFSO.CopyFolder strFavorites, strRestoreTo
			If Err.Number <> 0 Then
				WScript.Echo "Error " & Err.Number & ": " & Err.Description
			End If
			Err.Clear
			On Error GoTo 0
		Else
			WScript.Echo "Destination folder " & strRestoreTo & " not found."
		End If
	Else
		WScript.Echo "Source folder " & strFavorites & " not found."
	End If
End Sub

Open in new window


Regards,

Rob.
0
 
shorisAuthor Commented:
Thank you so much.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now