Jump to content

Recommended Posts

Posted
We have decided to delete all users files from their home dirrectorys. Does anyone have a script or utility to carry out this task?
Posted

Not sure if you really want to delete all user files (staff? administrator?) but you can use the following code to do that.

 

The key line contains:

 

If you take out "ou=to be deleted" then it will delete every file in every user's home directory - use with care!!!

 

If you've got an OU for each year group then you might use:

 

or

 

What I would do is to set up the code below but replace DeleteFolder sHomeDir with wscript.echo sHomeDir - you'll then see a list of folder names but they won't actually get deleted. When you're sure this is the right set of users you can go ahead and put back the delete line.

 

Just for info, I'm doing the delete a file at a time because if you try and delete a folder and 1 file is locked then the rest of the folder gets left behind. Like this, you might get a few odd files left behind to tidy up manually but most will be cleaned up.

 

Dim sRoot
Set oRootDSE=GetObject("LDAP://RootDSE")
sRoot=oRootDSE.Get("rootDomainNamingContext")
Set oFSO=wscript.createobject("scripting.filesystemobject")
Set oConn2 = CreateObject("ADODB.Connection")

oConn2.Provider = "ADsDSOObject"
oConn2.Open
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConn2
oCommand.properties("Page Size")=1000


oCommand.CommandText = ";(&(objectCategory=person)(sn=*));sAMAccountName,adspath,cn;subTree"
set oRS2=oCommand.execute
do while not oRS2.eof
 set oUser=getobject(ors2("adspath"))
 wscript.echo "deleting " & oUser.name
 sHomeDir=""
 on error resume next
 sHomeDir=ouser.get("homedirectory")
 on error goto 0
 if sHomeDir<>"" then
   if oFSO.folderexists(sHomeDir) then
   DeleteFolder sHomeDir
   end if
 oRS2.movenext
loop

Sub DeleteFolder(sRoot)
 on error resume next
 Set oFolder=oFso.getfolder(sRoot)
 For Each folder In oFolder.subfolders
     ClearContents(folder)
 Next
 ClearContents(oFolder)
 on error goto 0
end sub

Sub ClearContents(sFolder)
 on error resume next
 for each f1 in sFolder.files
   ofso.deletefile f1,true
 next
 For Each f2 In sFolder.subfolders
   ClearContents(f2)
   ofso.deletefolder f2,true
 Next
 on error goto 0
End Sub

Posted

@noser:

 

May I ask the question, why do you want to delete all user files from their home directory?

 

Have you already copied them to another place?

 

We copy our final year students work to another place and then back them up onto DVDs and Archive them as our Final year students may need the work for future use, then and only then do we delete from the servers. ;) :)

Posted
I do it because, no matter how much I try, I cannot get the kids to keep their folders tidy. So now I back everything onto dvd and then delete it from the server. If anyone needs a file they have to come to me and ask for it. In the 3 years or so I've been doing this, I haven't been asked once. This is just the students not staff.
Posted

@laserblazer:

 

Why would you be bothered about their personal space?

 

I find that if you give the students the right amount of space to save their work to and not too much it is up to the ICT teaching staff to ensure that the students create a folder structure which reflects a tidy solution. ;) :)

 

It is not up to us to say how they use the disk space allocated to them except for misuse in uploading illegal files or inappropriate material. :)

Posted

we just give em appropriate quota's with limits on the maximum file size, max no of files etc. They get email when over quota and have a 'grace period' to get their things in order.

 

ICT organisation is an important lifeskill, and less admin if you get your users to look after their own stuff ;)

Posted

ICT organisation is an important lifeskill, and less admin if you get your users to look after their own stuff ;)

 

and what did your mum say she'd do if you didn't keep your bedroom tidy?

 

As I said, nobody has ever asked for an old file back.

Posted

@laserblazer:

 

My Mum told me only once and then proceeded to let my room fill up with dirty clothes and other things, when I got sick of not having any clean clothes to wear or could not find anything it suddenly dawned on me to tidy things up.

 

It is only when someone else does it for you that you become lazy and will not do it yourself, as our end users eventually learn that to use IT effectively they themselves have to work at tidying their environment up.

 

Your not teaching them anything by taking things away, just that they have a clean space to mess up again. As has been mentioned IT is a lifeskill and something that has to be learned just like any other skill. ;) :)

Posted
During the holidays, our school had a deep clean and the painters are still here finishing off. The mess that the kids made emptying waste into the skip at the end of term has been cleaned up and the school is spick and span. I doubt the kids will notice this when they come back, same as most won't notice their folders are empty. They are told how to keep organised but they are 9/10 year olds and it doesn't sink in. The teachers don't reinforce it, so I just find it easier to start the year with a clean slate. It's not as if I am removing anything permanently.
Posted

There is a quota, it's not the running out of space that's the issue, it's more the half a dozen versions of the same powerpoint and multiples of images they have downloaded and will never use. I appreciate that they should be taught how to organise their work but it doesn't happen in practice.

 

Anyway, we are getting away from the point, the OP asked how to bulk delete user files and I said how I do it without resorting to scripts.

Posted

Anyway, we are getting away from the point, the OP asked how to bulk delete user files and I said how I do it without resorting to scripts.

 

But if you don't ask questions you never learn new and interesting things :-)

 

I understand what you are doing and why but I don't think it's a good idea. If users are running out of disc space then they need to delete stuff they don't use - it is a skill they need to learn.

 

If the files need deleting because a school can't afford enough disc space to give sensible quotas then the idea of deleting the content is reasonable (assuming it has been backed up somewhere just in case!)

 

Finally, while avoiding scripting can be a good idea and works well for a small school it's really not viable if you've got even 1,000 users let alone 10,000 or more (and many posters here do have that sort of network)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...