Solved

Script to "reset" a profile

Posted on 2011-03-08
3
377 Views
Last Modified: 2012-06-27
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.

0
Comment
Question by:garryshape
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 35079291
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.

Regards,

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

' 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
	Err.Clear
	On Error GoTo 0
End If

If blnBackup = False Then
	MsgBox "Unable to create " & strBackupFolder & VbCrLf & "Cannot back up folder."
Else
	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."
	Else
		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
	Next
	For Each objSubFolder In objFSO.GetFolder(strFolder).SubFolders
		objFSO.CopyFolder objSubFolder.Path, strBackupFolder, True
		'objFSO.DeleteFolder objSubFolder.Path, True
	Next
End If

Open in new window

0
 

Author Closing Comment

by:garryshape
ID: 35088185
AWESOME
THANK YOU
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35088306
No worries. Thanks for the grade.

Regards,

Rob.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question