• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
'****************************************************************'Created by Brian Bohanon'Created: 7/8/2008'Make department = physicalDeliveryOffice for all users in domain''Pseudo code:'Get all users, physicalDeliveryOffice into array'Print out to a log'For each item in the array'set user[i].department = user[i].physicalDeliveryOffice'print out user, deparment, physicalDeliveryOffice to a log'Next'****************************************************************Option ExplicitOn Error Resume NextDim objUser, objChild, objConnection, objRootDSE, objItemDim WshShell, objFSODim strRoot, strDNSDomain, strContainerDim strphysicalDeliveryOfficeName, strsAMAccountNameDim strdepartmentAfter, strDirectory, strdepartmentBeforeDim i, intLogFlagi = 1intLogFlag = 0'no log existsSet WshShell = CreateObject("WScript.Shell")'Set current directory to Desktop & display on pagestrDirectory = WshShell.SpecialFolders("Desktop") & "\"Set objRootDSE = GetObject("LDAP://RootDSE")strDNSDomain = objRootDSE.Get("DefaultNamingContext")strContainer = strContainer & strDNSDomain'To do a subcontainer, add it after//ou=OUName, - include commaset strRoot =GetObject("LDAP://" & strDNSDomain )'Start LoggingCreateLog()'****************************************************************For each objChild in strRootSelect Case objChild.classCase "organizationalUnit","container"Call DATreeEnd SelectNextSub DATree()For each objUser in objChildIf objUser.class="user" ThenstrphysicalDeliveryOfficeName = objUser.physicalDeliveryOfficeNamestrsAMAccountName = objUser.sAMAccountNamestrdepartmentBefore = objUser.departmentIf strphysicalDeliveryOfficeName <> "" ThenobjUser.Put "department", strphysicalDeliveryOfficeNameobjUser.SetInfo
 
strdepartmentAfter = objUser.departmentWriteLog(strphysicalDeliveryOfficeName), (strsAMAccountName),_(strdepartmentBefore), (strdepartmentAfter)i = i + 1End IfEnd ifnextEnd Subi = i -1Wscript.Echo "Accounts = " & iWscript.Quit'****************************************************************Sub CreateLog()On Error Resume NextDim objFileDim strFile, strText'Create log filestrFile = "UserDepartmentLog_" & Month(Date()) & "_" & Day(Date()) & ".txt"Set objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.CreateTextFile(strDirectory & strFile)Set objFile = Nothing'Write headers to the log filestrText = "User Name,Date,Office,Department Before, Department After"Set objFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True)objFile.WriteLine(strText)intLogFlag = 1Set objFSO = NothingSet objFile = NothingEnd Sub'****************************************************************'Used to append the log for each computer the script is run againstSub WriteLog(strOfficeName, strAccountName, strDeptBefore, strDeptAfter)On Error Resume NextDim objFile, objTextFileDim strFile, strTextstrFile = "UserDepartmentLog_" & Month(Date()) & "_" & Day(Date()) & ".txt"Set objFSO = CreateObject("Scripting.FileSystemObject")'Check to see if the log existsIf intLogFlag = 1 Then'Write to the logstrText = strAccountName & "," & Date() & "," & strOfficeName & "," &_
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...