Script to delete certain folders in roaming profiles.

I need a script that will delete only these folders located in \\domain\profiles.  Under the profiles directory we have hundreds of profiles, for each profile we need this folder and subfolders deleted.  Any batch or powershell scripts anyone have that can help?

Who is Participating?
Steve KnightIT ConsultancyCommented:
Try this.  Change the path at the top to point at your profiles share.   It works down a directory of all subdirs under that and does a loop for each.  Inside that loop it checks if each dir exists and if so shows it on screen then does an RD command on it including subdirs. asssuming that is what is wanted.  Any files in those dirs will go too of course.

As it stands the word ECHO in caps shows the RD command to the screen.  Make sure you are happy it is showing right then remove that word ECHO and it will run the commands instead.

Suggest running it on a copy of 5-10 profile dirs first say in a different subdir to make sure you are happy.


@echo off
REM put in the root path of your profiles area, this maps drive and changes to that dir.
pushd \\domain.local\profiles 
for /f "tokens=*" %%d in ('dir /b /ad') do (
  if exist "%%d\appdata\local\assembly" (
   echo Removing "%%d\appdata\local\assembly"
   ECHO RD /S /Q "%%d\appdata\local\assembly"
  if exist "%%d\appdata\Local\Microsoft\Windows\WebCache" (
   echo Removing "%%d\appdata\Local\Microsoft\Windows\WebCache"
   ECHO RD /S /Q "%%d\appdata\Local\Microsoft\Windows\WebCache"

Open in new window

Steve KnightIT ConsultancyCommented:
Thanks, did that work OK for you then?

mystikal1000Author Commented:
To be honest I haven't ran it yet, since I was so busy.  I gave you the points anyways, but I will test it soon.  They abandoned the question and I didn't want you to lose points.
Steve KnightIT ConsultancyCommented:
No problem. Just post back if you get any issues when you do try it.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.