Link to home
Start Free TrialLog in
Avatar of ivan rosa
ivan rosaFlag for United States of America

asked on

deleting users files

hello folks,
is there a way to create a script that will delete all USERS files (not folders) from their NT account ?

thanks,
Avatar of Edward Pamias
Edward Pamias
Flag of United States of America image

are files files server based?
Have you tried running Disk Cleanup using Task Scheduler?
ASKER CERTIFIED SOLUTION
Avatar of Scott C
Scott C
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok.  the del command didn't work in PS.  

So you can use the DEL in a batch file or you can use:

Get-ChildItem -Path C:\Temp -Include *.* -File -Recurse | foreach { $_.Delete()}

in PS.   I just tested the above command on Windows Server 2012 R2 and it work perfectly.  Deleted all of the file but left the folder structure intact.
Avatar of ivan rosa

ASKER

they are servers based,

my objective: delete all files users would create throught the day, at the end of the day

and if was possible to create a batch or vbs so I can add it on the task scheduling...
Yes.  See my comments above.
If the files are not subject to Disk Cleanup (and it looks like no) , then the folders need to be known , delete with a batch file and use Task Scheduler to run the batch file.
Actually John, only the parent folder needs to be known.

Using the two solutions I provided, it doesn't matter what the sub folders are.  The commands I provided, will when run in a batch file, script, remove the files but leave the folder structure in place.

This way even if the users create their own sub-folders the files will be removed.  If it has to be done folder specific, then if they create a new folder that isn't part of the "known" group the files in those folders will be deleted as well.
hmm what If I need to apply it from a computerlist.txt?
Do you mean from a list of computers?

Just build your batch/script file with the specific computer names.

They aren't going to change that often are they?
Here's how to ping computers in a .txt file.

I'm sure you could modify the script to run the DEL command instead of PING.

http://www.computing.net/answers/programming/ping-list-of-computers-from-a-txt-file/19843.html
thanks Scottcha, for giving me a clue

I ended up creating a script like this
del /S /Q "c:\Users\*.xlsx" >nul 2>&1
Anytime.