Vbscript - Creating a script that mirrors several sets of folders

Posted by Kenny Bones on Stack Overflow See other posts from Stack Overflow or by Kenny Bones
Published on 2010-05-21T08:42:42Z Indexed on 2010/05/28 11:31 UTC
Read the original article Hit count: 381

Ok, this is my problem. I'm doing a logonscript that basically copies Microsoft Word templates from a serverpath on to a local path of each computer. This is done using a check for group membership.

If MemberOf(ObjGroupDict, "g_group1") Then
    oShell.Run "%comspec% /c %LOGONSERVER%\SYSVOL\mydomain.com\scripts\ROBOCOPY \\server\Templates\Group1\OFFICE2003\ " & TemplateFolder & "\" & " * /E /XO", 0, True
End If

Previously I used the /MIR switch of robocopy, which is exellent. But, if a user is member of more than one group, the /MIR switch removes the content from the first group, since it's mirroring the content from the second group. Meaning, I can't have both contents.

This is "solved" by not using the /MIR switch and just let the content get copied anyway. BUT the whole idea of having the templates on a server is so that I can control the content the users receive through the script. So if I delete a file or folder from the server path, this doesn't replicate on the local computer. Since I don't use the /MIR switch anymore. Comprende?

So, what do I do? I did a small script that basically checks the folders and files and then removes them accordingly, but this actually ended up being the same functionality as the /MIR switch anyway. How do I solve this problem?

Edit: I've found that what I actually need is a routine that scans my local template folder for files and folders and checks if the same structure exists in any of the source template folders.

The server template folders are set up like this:

\\fileserver\templates\group1\
\\fileserver\templates\group2\
\\fileserver\templates\group3\
\\fileserver\templates\group4\
\\fileserver\templates\group5\
\\fileserver\templates\group6\

And the script that does the copying is structures like this (pseudo):

If User is MemberOf (group1) Then
   RoboCopy.exe \\fileserver\templates\group1\ c:\templates\workgroup *.* /E /XO
End if

If User is MemberOf (group2) Then
   RoboCopy.exe \\fileserver\templates\group2\ c:\templates\workgroup *.* /E /XO
End if

If User is MemberOf (group3) Then
   RoboCopy.exe \\fileserver\templates\group3\ c:\templates\workgroup *.* /E /XO
End if

Etc etc With the /E switch, I make sure it copies subfolders as well. And the /XO switch only copies files and folders that are newer than those in my local path. But it doesn't consider if the local path contains files or folders that doesn't exist on the server template path.

So after the copying is done, I would like to check if any of the files or folders on my c:\templates\workgroup actually exists in either of the sources. And if they don't, delete them from my local path. Something that could be combined in these memberchecks perhaps?

© Stack Overflow or respective owner

Related posts about vbscript

Related posts about active-directory