Login | |
|
 |
Re: home directory permissions script folder exception - 5/3/2005 8:31:00 AM
|
|
 |
|
| |
esnmb
Posts: 448
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
|
I have a script that does this already. I search folders that are named after user accounts, then a match the folder names to user names, move the folders to a new server and ACL them with MS' SubInACL tool. I also supply a security group to the script so I can pick and choose what users are to be moved. If this doesn't help, I also have a script to read an Excel spreadsheet for user names and copy folders and ACL them. That particular script will allow you to move users based on their first initial. Any way, here is the first one I talked about: Start = Now ' ************************************** ' * Prompt user for Group to search in * ' ************************************** strGroup = InputBox("Please enter the Group to search through.", "Active Directory Group Search") 'strGroup = "Ctxusr Midd01fs" Const ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile("\\DOMAIN-share\users\TimeReport-" & strGroup & ".log", ForWriting) ' ********************************* ' * Error handling for user input * ' ********************************* Const TIMEOUT = 10 Const POPUP_TITLE = "Input Error" Set objScript = Wscript.CreateObject("Wscript.Shell") If strGroup = "" Then iRetVal = objScript.Popup( "You must enter a Group name to search through." & _ vbCrLf & "Would you like to enter it now?",TIMEOUT,POPUP_TITLE,vbQuestion + vbYesNo) End If Select Case iRetVal Case vbYes strGroup = InputBox("Please enter the Group you wish to search through.", "Active Directory Group Search") Case vbNo Wscript.Quit Case -1 MsgBox "** POPUP TIMED OUT **" & vbCrLf & vbCrLf & "No files have been copied.",, "Notification Message" wscript.Quit End Select ' *************** ' * Script Main * ' *************** Set objFSO = CreateObject("Scripting.FileSystemObject") Set objGroup = GetObject _ ("LDAP://CN=" & strGroup & ",OU=General,OU=Security Groups,DC=DOMAIN,DC=com") objGroup.GetInfo ' Retrieves members of specified Group arrMember = objGroup.GetEx("member") ' Defines the different OU's that contain user accounts Set objOU = GetObject("LDAP://OU=Users,OU=All Users,DC=DOMAIN,DC=com") objOU.GetInfo Set objOU1 = GetObject("LDAP://OU=Admins,OU=All Users,DC=DOMAIN,DC=com") objOU1.GetInfo Set objOU2 = GetObject("LDAP://OU=Executives,OU=All Users,DC=DOMAIN,DC=com") objOU2.GetInfo Set objOU3 = GetObject("LDAP://OU=Emax Recipients,OU=Users,OU=All Users,DC=DOMAIN,DC=com") objOU3.GetInfo Set objOU4 = GetObject("LDAP://OU=MLN Recipients,OU=Users,OU=All Users,DC=DOMAIN,DC=com") objOU4.GetInfo arrLDAP = Array(objOU, objOU1, objOU2, objOU3, objOU4) ' Defines the paths to user folders objPath = "\\midd01fs\vol3\Oakbrook\Users\" objPath1 = "\\midd01fs\vol3\Atlanta\Users\" objPath2 = "\\midd01fs\vol3\Horsham\Users\" objPath3 = "\\midd01fs\vol1\Users\" objPath4 = "\\Midd01bs\vol1\Delaware\Users\" objPath5 = "\\Midd01bs\vol1\Phoenix\Users\" objPath6 = "\\Midd01bs\vol1\Retail\Users\" objPath7 = "\\Midd01bs\vol1\Referral\Users\" arrPath = Array(objPath, objPath1, objPath2, objPath3, objPath4, objPath5, objPath6, objPath7) ' Loops from 0 to as many item as there are in the Array For i = 0 To UBound(arrLDAP) For Each objItem In arrLDAP(i) objMembers = LCase(Join(arrMember)) strName = LCase(objItem.DistinguishedName) If InStr(objMembers, strName) Then ' Copying files and folders For Each Path In arrPath strFolder = Path & objItem.SamAccountName strDest = "\\DOMAIN-share\users\" & objItem.SamAccountName If objFSO.FolderExists(strFolder) Then ' When disabling display of "Percent Complete" with switch, Robocopy hangs on large files. objScript.Run ("robocopy.exe " & strFolder & " " _ & strDest & " /MIR /R:5 /NC /LOG+:CopyReport.log /TEE"), 1, True objFile.WriteLine "Copied: " & objItem.SamAccountName End If Next ' Setting permissions on only the folders copied in this batch If objFSO.FolderExists(strDest) Then objScript.Exec ("SubInACL.exe /subdirectories " & strDest _ & " /grant=DOMAIN\" & objItem.SamAccountName & "=C") End If End If Next Next If DateDiff("n", Start, Now) = 0 Then objFile.WriteBlankLines 1 objFile.WriteLine "The script took less than 0 minutes to complete." & vbCrLf objFile.WriteLine "There may have been a problem or the group that was entered does not exist." objFile.Close Else objFile.WriteBlankLines 1 objFile.WriteLine "======================" objFile.WriteLine "======================" objFile.Write DateDiff("n", Start, Now) & " minutes to complete" objFile.Close End If
< Message edited by esnmb -- 1/2/2007 5:38:05 AM >
|
|
| |
|
|
|
 |
Re: home directory permissions script folder exception - 5/3/2005 8:32:26 AM
|
|
 |
|
| |
esnmb
Posts: 448
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
|
Here is the other one to get user/folder names from an Excel Spreadsheet and move and ACL them. ' ******************************************************** ' * Prompt to get the first initial of the users to copy * ' ******************************************************** strInitial = InputBox(vbCrLf & vbCrLf & vbCrLf & _ "Please enter the first initial of the users you wish to copy.","Folder Copy") 'strInitial = "a" If strInitial = "" Then Wscript.Echo "You must enter an initial to begin the copy." & vbCrLf & "Script is exiting." Wscript.Quit End If ' ********************* ' * Script start time * ' ********************* Start = Now ' *************** ' * Script Main * ' *************** Const ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.CreateTextFile("\\DOMAIN-share\TestShare\TimeReport_Midd01fs - " & Left(UCase(strInitial), 1) _ & ".log", ForWriting) Set objScript = Wscript.CreateObject("Wscript.Shell") objPath = "\\midd01fs\vol1\Users\" Set objExcel = CreateObject("Excel.Application") strPathExcel = "c:\temp\midd01fsusers.xls" objExcel.Workbooks.Open strPathExcel NumofSheet = objExcel.ActiveWorkbook.Sheets.Count For s = 1 To NumofSheet objExcel.ActiveWorkbook.Sheets(s).Select Set objSheet = objExcel.ActiveWorkbook.Activesheet For intRow = 1 To objSheet.UsedRange.Rows.Count strData= LCase(Trim(objSheet.Cells(intRow,1).Value)) If Left(strData, 1) = Left(LCase(strInitial), 1) Then strFolder = objPath & strData strDest = "\\DOMAIN-share\TestShare\" & strData If objFSO.FolderExists(strFolder) Then objScript.Run ("robocopy.exe " & strFolder & " " _ & strDest & " /Create /E /R:5 /NC /LOG+:CopyReport.log /TEE"), 1, True objFile.WriteLine "Copied: " & strData End If If objFSO.FolderExists(strDest) Then objScript.Exec ("SubInACL.exe /subdirectories " & strDest _ & " /grant=DOMAIN\" & strData & "=C") End If End If Next Next ' ************************************************************************* ' * Updates log with time to complete as well as a form of error handling * ' ************************************************************************* If DateDiff("n", Start, Now) = 0 Then objFile.WriteBlankLines 1 objFile.WriteLine "The script took less than 0 minutes to complete." & vbCrLf objFile.WriteLine "There may have been a problem or the initial that was entered, " & Chr(34) _ & strInitial & Chr(34) & " does not exists." objFile.Close Else objFile.WriteBlankLines 1 objFile.WriteLine "======================" objFile.WriteLine "======================" objFile.Write DateDiff("n", Start, Now) & " minute(s) to complete" objFile.Close End If objExcel.Quit
< Message edited by esnmb -- 1/2/2007 5:38:19 AM >
|
|
| |
|
|
|
|
|