Solved

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)

Posted on 2008-06-12
10
210 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:jonathanpace
10 Comments
 
LVL 9

Expert Comment

by:authen-tech
ID: 21776014
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
 

Author Comment

by:jonathanpace
ID: 21776084
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
 

Author Comment

by:jonathanpace
ID: 21776132
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
 
LVL 7

Expert Comment

by:ManicD
ID: 21777526
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
Does Powershell have you tied up in knots?

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

 

Author Comment

by:jonathanpace
ID: 21777688
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
 
LVL 22

Accepted Solution

by:
Paka earned 125 total points
ID: 21782467
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
 

Assisted Solution

by:WendyDun
WendyDun earned 125 total points
ID: 21810222
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
 

Author Comment

by:jonathanpace
ID: 21851017
I will try this and get back to you. Thanks for your help.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Resolve DNS query failed errors for Exchange
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now