PTD Posted June 4, 2008 Posted June 4, 2008 Hi I am after a VB script that will check all folders within a folder called G:\Profiles and delete those that are have the name Username.Domain_nfrs We have slow replication and sometimes a user profile folder gets created twice, the second time with the _nfrs appended to the folder. I would like to delete this. Can anyone possibly help? and wouldn't mind explaining what each part does? Thanks:drunken_smilie: I'm new to scriptin
PTD Posted June 4, 2008 Author Posted June 4, 2008 Thanks, appreciate answer but for some reason these don't take care of themselves so we end up with a few replicated files.. hebce the need to delete them, we been doing it manually so far.. but it'ss a pain!!
maniac Posted June 4, 2008 Posted June 4, 2008 Try these two lines of VB script, they will remove all folders and their contents where the folder ends in _nfrs Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.DeleteFolder("G:\profiles\*_nfrs.*") mike.
apeo Posted June 4, 2008 Posted June 4, 2008 (edited) Heres a vbs version of the same thing: Dim Path Dim fso: Set fso = CreateObject("Scripting.FileSystemObject") Path = WScript.Arguments(0) DeleteFolders(Path) Public Function DeleteFolders(Byval Path) Dim n: n = 0 Dim Folder: Set Folder = fso.GetFolder(Path) DeleteFolder(Folder) SearchSubfolder(Folder) set Folder = nothing End Function Public Function SearchSubfolder(Folder) dim SubFodlers: Set Subfolders = Folder.subfolders dim Subfolder For each Subfolder in Subfolders DeleteFolder(SubFolder) SearchSubfolder(Subfolder) next set Subfolders = nothing End Function Public Function DeleteFolder(Folder) Dim Files: Set Folders = Folder.subfolders Dim i: i = Folders.Count Dim CheckFolder Dim CheckPath For Each CheckFolder In Folders If instr(checkfolder.name,"_nfrs") Then fso.deletefolder checkfolder.path end if Next Set Folders = Nothing End Function Usage: In command prompt - cscript nameofscript.vbs "Path" eg cscript nameofscript.vbs "g:\profiles" NOTE: This will recursively search all folders in the root folder for folders with the name of "*_nfrs*" and delete it, use with care/at your own risk. Edited June 4, 2008 by apeo 1
PTD Posted June 4, 2008 Author Posted June 4, 2008 Hi It still doesn't delete the folder.. I'm trying it on a test box at moment the username appears in Killprofile.txt but doesn't delete folder. Manic is that all i need or is there more??
maniac Posted June 4, 2008 Posted June 4, 2008 (edited) There's a GPO setting that allows you to let admin users have access to profiles as well as the user the profile belongs to. We have this set, and it solves a lot of problems with accessing stuff when we need to. It only works when the profile is created by the network for the first time however, so switching it on won't alter the permissions on profiles you already have. However you can run a XCALS command on the necessary folders to do this, but be careful as in my experience it's easy to mess up permissions on profile folders, then they won't work properly! That VBS script I posted should just work as is, as long as the user running it has access to the folder its deleting of course! Please test it somewhere non-critical first thou! Mike. Edited June 4, 2008 by maniac 1
PTD Posted June 4, 2008 Author Posted June 4, 2008 Brillaint, the script works Many Thanks to the both of you for your help.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now