Solved

Script to "reset" a profile

Posted on 2011-03-08
3
374 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
Comment Utility
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
Comment Utility
AWESOME
THANK YOU
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
No worries. Thanks for the grade.

Regards,

Rob.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now