gpo windows 2003 server - deleting all files older than a week on a workstation group

Hello people! This is situation...
2003 domain, about 70 client. almost 15 client using a cad application, producing a lot of temp files i'll need to delete everytime.
These files could be useful in some cases, so i think to preserve last week.

So i need to deploy a gpo:
- only for 15 client, not by user but by computer
(i need to create an OU??)
- run batch/gpo at login or logoff
- control presence of a particular folder (c:\tempCad), making it if there isn't
- deleting all files in that folder, leaving only last week

Ask me for details me please!!
Mattia MinerviniAsked:
Who is Participating?
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.

Here is a script that will create the folder if it's not present, and delete files in it if their creation date is older then 7 days.

You can appoint this as a logon script (user based).

You should offcourse test it before doing anything :)

(save as .vbs)
strComputer = "."
on error resume next
Dim fso, f
fldr = "C:\tempCAD"
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FolderExists(fldr) = False) Then
   Set f = fso.CreateFolder(fldr)
End If

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='C:\tempCAD'} Where " _
        & "ResultClass = CIM_DataFile")

strCurrentDate = Now

For Each objFile In colFiles
    strFileDate = WMIDateStringToDate(objFile.CreationDate)
    intDay = DateDiff("d", strFileDate, strCurrentDate)
    If intDay > 2 Then
    End If

Function WMIDateStringToDate(dtmInstallDate)
    WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _
        Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _
            & " " & Mid (dtmInstallDate, 9, 2) & ":" & _
                Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _
                    13, 2))
End Function

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
Change this line:

If intDay > 2 Then
to If intDay > 7 Then

forgot to change it back while testing..
Mattia MinerviniAuthor Commented:
Thanks snus....
seems to work locally. It no delete subfolder (this could not be a problem) but i prefer computer based and no user based (some users could manage other workstations).
I cannot understand well if i'm forced to create an OU in windows 2003 to deploy a gpo on a subset of computer/user
Could you use a scheduled task (ie. GPP) or you could try a startup script which is computer based.
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
Windows Server 2003

From novice to tech pro — start learning today.