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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.