Solved

Script to "reset" a profile

Posted on 2011-03-08
3
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

733 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