Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Script to "reset" a profile

Posted on 2011-03-08
3
Medium Priority
?
382 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

705 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