Oops_my_bad Posted May 5, 2009 Posted May 5, 2009 I've been asked about copying a folder full of stuff in certain student areas for our functional ICT exam. The problem is I don't want it going in everyones - just a small selection. I'm guessing I need some sort of "for" loop which only operates on given student areas -but not sure how to go about this:confused: Be grateful if anyone can help!? :confused:
K.C.Leblanc Posted May 5, 2009 Posted May 5, 2009 (edited) The easiest way to do this would probably to put the particular users in a different OU (it could even a child OU) and then add an extra GPO that runs the script. Is this something you want to run once or everytime they log on. If it's something you only need to do once another quick and dirty method is to use the CONCATENATE function in Excel to build a batch script that'll do what you need. Edited May 5, 2009 by K.C.Leblanc
mac_shinobi Posted May 5, 2009 Posted May 5, 2009 (edited) you could do something similiar to using a boolean inside of a for loop as per here Delete Local Profiles (VBScript) Const LocalDocumentsFolder = "C:\Documents and Settings\" set objFSO = createobject("Scripting.FileSystemObject") set objFolder = objFSO.GetFolder(localdocumentsfolder) on error resume next for each fldr in objFolder.SubFolders if not isexception(fldr.name) then objFSO.DeleteFolder fldr.path, True end if next Function isException(byval foldername) select case foldername case "All Users" isException = True case "Default User" isException = True case "LocalService" isException = True case "NetworkService" isException = True case "Administrator" isException = True case Else isException = False End Select End Function You would need to alter the function a bit so that it got the usernames instead of folder names and if the isException is = to true then it wont delete it and if it is = false then it will delete it. However in your case you would alter the code above to copy instead of delete. Edited May 5, 2009 by mac_shinobi
srochford Posted May 5, 2009 Posted May 5, 2009 Easier to put users in security groups than OUs - you can only be in 1 OU but multiple groups. Code below looks for users in group called "ma users" and copies the file listed at the start (c:\temp\special.doc) into their homedir. Not sure if that's the sort of thing you're trying to do. sGroup="ma users" sFile="c:\temp\special.doc" set ofso=createobject("scripting.filesystemobject") Set oRootDSE=GetObject("LDAP://RootDSE") sRoot=oRootDSE.Get("DefaultNamingContext") Set oConn = CreateObject("ADODB.Connection") oConn.Provider = "ADsDSOObject" oConn.Open Set oCommand = CreateObject("ADODB.Command") oCommand.ActiveConnection = oConn oCommand.properties("Page Size")=100 oCommand.CommandText = ";(sAMAccountName=" & sGroup & ");sAMAccountName,distinguishedname;subTree" on error resume next Set oRS = oCommand.Execute if not ors.eof then wscript.echo ors("distinguishedname") set oGroup=getobject("LDAP://" & ors("distinguishedname")) for each oMember in ogroup.members set oUser=getobject("LDAP://" & oMember.distinguishedname) sHomeDir=oUser.homedirectory ofso.copyfile sFile, sHomeDir, true next end if
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now