How do I make a script to delete files I specify, from hundreds of different directories? (Or a program that will do it for me)

Hi Experts

I'm a systems administrator at a school with over 1000 student accounts. We've had quite a number of kids bringing games and unwanted material into the school, and storing it on their home drives.

What I would like to do is have a utility that scans all these folders at night time looking for files I specify, and delete them. A Batch file or something. I have a large list of files that I know I wan't removed without question (like quake system files, flash games etc) I just need to give them to a program to deal with them.

Can anyone help, or suggest some software that will do this for me?

Kind of like a Virus scanner, but one that allows me to specify what it scans for.

Thanks

Jono
jonathanpaceAsked:
Who is Participating?
 
PakaConnect With a Mentor Commented:
Since you're only looking for file names, the batch delete method should only scan the MFT (not the entire disk) and won't flog your drives too badly.

You might be able to create virus signatures for the "bad" software and add it to the virus signatures.  I know that the Symantec SMTP anti-virus lets you define bad software names and it will quarratine/delete these files.
0
 
authen-techCommented:
You might want to look into something like the Shared Computer Toolkit (now known as SteadyState)
http://www.microsoft.com/downloads/details.aspx?FamilyId=D077A52D-93E9-4B02-BD95-9D770CCDB431&displaylang=en

It will let you lock down the computers after you get them cleaned up and not allow for the installation of such files.  
0
 
jonathanpaceAuthor Commented:
Thats not what I am after. The computers are locked down tight.

The students are copying things from USB memory keys onto their home drives. Movies, games that don't need to be installed, etc.

I want something server side where the home folders are stored to hunt down and destroy these kinds of things at night time.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
jonathanpaceAuthor Commented:
oh, whatever I use needs to be able to search for things I specify, because we can't just go and delete "*.wmv" and things like that because there are student assignments that are stored in the format etc.

Are there any programs out there?
0
 
ManicDCommented:
You could try a software restriction policy. it wouldnt remove the files but it would stop them being accessable to students. Then afater a while once the theory that they can be used has spread a simple windows search and delete should remove the rubbish.


More information.
http://support.microsoft.com/kb/324036
http://technet.microsoft.com/en-us/library/bb457006.aspx
0
 
jonathanpaceAuthor Commented:
I don't need any restriction policies as everything is locked down via group policy.

And installing software on individual PC's is out of the question, as there is over 1000 of them..

I need something server side, that will search for files that I specify in a bulk list. That way I can run it every night to remove any software automatically that I have specified in this list.

Will be easy because we have one server storing all the home folders, so it would just trawl through these folders deleting the stuff specified.

I was going to write a batch file and use "/s" commands, but if I specified 100 different files, then it would have to trawl through over 1000+ folders one at a time searching 100 times, and that would take too long and kill the disks from excessive flogging every night.


I'm running out of ideas..
0
 
WendyDunConnect With a Mentor Commented:
Use Powershell and have a script something like the following.

You can modify it to work on whole directories as well - simply pass a high level directory name in as the filter and add the "-recurse" option to the Remove-Item line.
Function delFiles ($TargetFolder, $filter)
{
    $files = get-childitem $TargetFolder -recurse -filter $filter
    if ($files -eq $null) {return} #oddly, if nothing is returned, the foreach will do one iteration
    foreach ($f in $files)
    {
        write-host "Deleting File $f" -foregroundcolor "Red"
        Remove-Item $f.FullName -force # force ensures that readonly files are deleted. 
    }
}
 
# the filter will accept wildcards or exact matches
delFiles "c:\" "*.bad" 
delFiles "c:\" "FileNamed.xxx"

Open in new window

0
 
jonathanpaceAuthor Commented:
I will try this and get back to you. Thanks for your help.
0
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.