troubleshooting Question

Help with VBS script

Avatar of lacroix_al
lacroix_al asked on
Visual Basic.NETVB Script
11 Comments1 Solution349 ViewsLast Modified:
I have this VBS script and can not figure out why it doesn't copy the data from the old folder to the new folder. can someone take a look and see what the issue is?
Sub onPostMove(Request)

If Request.class <> "user" Then Exit Sub
On Error Resume Next

Dim filesys, searchstr, newfolderpath, oldfolderpath, strname, DescName, oldscriptpath, olddescription, newcompany, newdescription


DirObj.Getinfo
objName=DirObj.Get("sAMAccountName")
cnpath=DirObj.Get("distinguishedName")
oldfolderpath=Dirobj.Get("division")
oldscriptpath=dirObj.Get("scriptpath")
olddescription=DirObj.Get("description")


DirObj.put "company", oldscriptpath
DirObj.put "department", olddescription

'DirObj.put "scriptpath", "RHS_Student.bat"
DirObj.put "scriptpath", "RHS_Stu_login.vbs"
DirObj.put "description", "RHS Student"
DirObj.setinfo



strName = objName

'Move from SPHS to RHS

searchstr = "RHS"

If Not InStr(cnpath, searchstr) = 0 Then

newfolderpath = "\\04infdata01\RHS_STU_HOME\" & strname

'DirObj.put "scriptpath", "RHS_Student.bat"
DirObj.put "scriptpath", "RHS_Stu_login.vbs"
DirObj.put "title", newfolderpath
DirObj.setinfo

'Add Users to Group
 
 
Set objUser = GetObject("LDAP://" & cnpath)
Set objGroup = GetObject("LDAP://CN=8e6Student,CN=Builtin,DC=sphs,DC=spuhsd,DC=k12,DC=ca,DC=us") 
objGroup.add(objUser.ADsPath)

Set objUser = GetObject("LDAP://" & cnpath)
Set objGroup = GetObject("LDAP://CN=RHSStudent,CN=Builtin,DC=sphs,DC=spuhsd,DC=k12,DC=ca,DC=us")
objGroup.add(objUser.ADsPath)


'Remove Users from Group

Set objUser = GetObject("LDAP://" & cnpath)
Set objGroup = GetObject("LDAP://CN=library,CN=Builtin,DC=sphs,DC=spuhsd,DC=k12,DC=ca,DC=us") 
objGroup.remove(objUser.ADsPath)

Set objUser = GetObject("LDAP://" & cnpath)
Set objGroup = GetObject("LDAP://CN=Students,CN=Builtin,DC=sphs,DC=spuhsd,DC=k12,DC=ca,DC=us")
objGroup.remove(objUser.ADsPath)



            
                
            Set filesys=CreateObject("Scripting.FileSystemObject") 
                              
                               ' creates folder if it doesn't exist 
                                If  Not filesys.FolderExists(newfolderpath) Then 
                                    Set newfolder = filesys.CreateFolder(newfolderpath)
                                End If
                                
                Set objShell = CreateObject("Wscript.Shell")
                Set objFSO = CreateObject("Scripting.FileSystemObject")
                If objFSO.FolderExists(newfolderpath) Then
                
                ' Assign user permission to home folder.
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /t /c /g sphs.spuhsd.k12.ca.us\" & strname & ":C ", 2, True)
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /e /c /g sphs.spuhsd.k12.ca.us\administrator:F ", 2, True)
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /e /c /g sphs.spuhsd.k12.ca.us\Domain_admins:F ", 2, True)
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /e /c /g 04infdata01\administrator:F ", 2, True)
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /e /c /g sphs.spuhsd.k12.ca.us\rhsteacher:C ", 2, True)
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /e /c /g System:F ", 2, True)
                      
                      End If
                      
                      
                      
                      
                      
                 
                Set filesys=CreateObject("Scripting.FileSystemObject") 
                                If filesys.FolderExists(oldfolderpath) Then 
                                filesys.copyFolder oldfolderpath, newfolderpath
                                filesys.deleteFolder oldfolderpath
                                End If
      
      

End If

'Move from RHS To SPHS

searchstr = "SPHS"

If Not InStr(cnpath, searchstr) = 0 Then


DirObj.Getinfo
newfolderpath=Dirobj.Get("division")
oldfolderpath=DirObj.get("title")
newdescription=DirObj.get("department")
newscriptpath=DirObj.get("company")

DirObj.put "scriptpath", newscriptpath
DirObj.put "description", newdescription
DirObj.setinfo



'Remove Users to Group
 
 

Set objUser = GetObject("LDAP://" & cnpath)
Set objGroup = GetObject("LDAP://CN=RHSStudent,CN=Builtin,DC=sphs,DC=spuhsd,DC=k12,DC=ca,DC=us")
objGroup.remove(objUser.ADsPath)



'Add Users from Group

Set objUser = GetObject("LDAP://" & cnpath)
Set objGroup = GetObject("LDAP://CN=library,CN=Builtin,DC=sphs,DC=spuhsd,DC=k12,DC=ca,DC=us") 
objGroup.add(objUser.ADsPath)

Set objUser = GetObject("LDAP://" & cnpath)
Set objGroup = GetObject("LDAP://CN=Students,CN=Builtin,DC=sphs,DC=spuhsd,DC=k12,DC=ca,DC=us")
objGroup.add(objUser.ADsPath)



                    
            Set filesys=CreateObject("Scripting.FileSystemObject") 
                              
                               ' creates folder if it doesn't exist 
                                If  Not filesys.FolderExists(newfolderpath) Then 
                                    Set newfolder = filesys.CreateFolder(newfolderpath)
                                End If
                                
                Set objShell = CreateObject("Wscript.Shell")
                Set objFSO = CreateObject("Scripting.FileSystemObject")
                If objFSO.FolderExists(newfolderpath) Then
                
                ' Assign user permission to home folder.
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /t /c /g sphs.spuhsd.k12.ca.us\" & strname & ":C ", 2, True)
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /e /c /g sphs.spuhsd.k12.ca.us\administrator:F ", 2, True)
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /e /c /g sphs.spuhsd.k12.ca.us\SPhsTeacher:C ", 2, True)
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /e /c /g 04infdata01\administrator:F ", 2, True)
                                intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & newfolderpath & " /e /c /g System:F ", 2, True)
                      
                      End If
                      
                      
                      
                      
                      
                 
                Set filesys=CreateObject("Scripting.FileSystemObject") 
                                If filesys.FolderExists(oldfolderpath) Then 
                                filesys.copyFolder oldfolderpath, newfolderpath
                                'filesys.deleteFolder oldfolderpath
                                End If
      
      

End If

Wscript.quit

    

End Sub
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros