Script to "reset" a profile

I'm trying to piece together a script that will do the following, and am wondering if anyone out there has a similar script they could share so I can test and hopefully use:

1. Display input box where you put a user's domain user account name
2. Confirm the name is correct, else go back to text box to re-enter
3. Take the username and make a backup of and delete a network folder (\\fs001\%username%$\Application Data\Microsoft) - the Microsoft folder backs up and deletes.
4. Take same username and make a backup of and delete all the "contents" (not the folder) of (\\fs002\profiles$\%username%) so the %username% folder still exists int he profiles$, but the contents is backed up and deleted.
5. Message saying complete. Or give an error if access to delete said folders is denied.

Who is Participating?
RobSampsonConnect With a Mentor Commented:
Hi, this won't delete anything yet, because all of the objFSO.DeleteFile and objFSO.DeleteFolder statements are commented out, but give it a shot and see if it works for you.  Set strBackupFolder to the folder to copy the files to.


blnConfirmed = vbNo
While blnConfirmed = vbNo
	strUsername = InputBox("Enter username:", "Username")
	blnConfirmed = MsgBox("You entered: " & strUsername & VbCrLf & "Is this correct?", vbYesNo, "Confirm Username")

' Set your destination backup folder here
strBackupFolder = "\\fs001\Backups\" & strUsername & "\"

Set objFSO = CreateObject("Scripting.FileSystemObject")
blnBackup = True
If objFSO.FolderExists(strBackupFolder) = False Then
	On Error Resume Next
	objFSO.CreateFolder strBackupFolder
	If Err.Number <> 0 Then blnBackup = False
	On Error GoTo 0
End If

If blnBackup = False Then
	MsgBox "Unable to create " & strBackupFolder & VbCrLf & "Cannot back up folder."
	If Right(strBackupFolder, 1) <> "\" Then strBackupFolder = strBackupFolder & "\"
	strFolder = "\\fs001\" & strUsername & "$\Application Data\Microsoft"
	If objFSO.FolderExists(strFolder) = False Then
		MsgBox strFolder & " does not exist. Cannot back up folder."
		objFSO.CopyFolder strFolder, strBackupFolder, True
		'objFSO.DeleteFolder strFolder, True
	End If
	strFolder = "\\fs002\profiles$\" & strUsername
	For Each objFile In objFSO.GetFolder(strFolder).Files
		objFSO.CopyFile objFile.Path, strBackupFolder, True
		'objFSO.DeleteFile objFile.Path, True
	For Each objSubFolder In objFSO.GetFolder(strFolder).SubFolders
		objFSO.CopyFolder objSubFolder.Path, strBackupFolder, True
		'objFSO.DeleteFolder objSubFolder.Path, True
End If

Open in new window

garryshapeAuthor Commented:
No worries. Thanks for the grade.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.