我有一个脚本,它应该将Description
的值复制到Department
。 但脚本似乎只能工作50%。我有OU
,有3个子OU
的。 该脚本只更改第一个OU
用户属性,但不更改其他2. 有人可能会检查脚本并告诉我它最新的错误。活动目录复制用户属性
脚本:
Option Explicit
On Error Resume Next
Dim objUser, objChild, objConnection, objRootDSE, objItem
Dim WshShell, objFSO, strRoot, strDNSDomain, strContainer
Dim strDescription, strsAMAccountName
Dim strdepartmentAfter, strDirectory, strdepartmentBefore
Dim i, intLogFlag 'no log exists
i=1
intLogFlag = 0
Set WshShell = CreateObject("WScript.Shell")
'Set current directory to Desktop & display on page
strDirectory = 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 comma
Set strRoot =GetObject("LDAP://OU=Kasutajad," & strDNSDomain)
'Start Logging
CreateLog()
'****************************************************************
For each objChild in strRoot
Select Case objChild.class
Case "organizationalUnit","container"
Call DATree
End Select
Next
Sub DATree()
OU.Filter="objectClass=user"
For each user in OU
If user.class="user" Then
On Error Resume Next
user.Department=user.description
If Err.Number = 0 Then
user.SetInfo
WScript.Echo "Copied:" & user.description & " for " & user.name
Else
On Error GoTo 0
WScript.Echo "No IPPHONE configured for " & user.name
End If
On Error GoTo 0
end if
i=i+1
next
End Sub
i = i -1
Wscript.Echo "Accounts = " & i
Wscript.Quit
'****************************************************************
Sub CreateLog()
On Error Resume Next
Dim objFile
Dim strFile, strText
'Create log file
strFile = "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 file
strText = "User Name,Date,Description,Department Before, Department After"
Set objFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True)
objFile.WriteLine(strText)
intLogFlag = 1
Set objFSO = Nothing
Set objFile = Nothing
End Sub
'****************************************************************
'Used to append the log for each computer the script is run against
Sub WriteLog(strdescription, strAccountName, strDeptBefore, strDeptAfter)
On Error Resume Next
Dim objFile, objTextFile
Dim strFile, strText
strFile = "UserDepartmentLog_" & Month(Date()) & "_" & Day(Date()) & ".txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Check to see if the log exists
If intLogFlag = 1 Then
'Write to the log
strText = strAccountName & "," & Date() & "," & strDescription & "," & strDeptBefore & "," & strDeptAfter
Set objFile = objFSO.OpenTextFile(strDirectory & strFile, 8, True)
objFile.WriteLine(strText)
objFile.Close
'Reset strText for later use
strText = ""
Else 'If the log doesn't exist, create it
CreateLog()
'Reset strText for later use
strText = ""
End If
Set objTextFile = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub