J'ai un script qui doit copier la valeur Description
à Department
. Mais le script ne semble fonctionner qu'à 50%. J'ai OU
, et il y a 3 sous OU
. Le script ne modifie que les premiers attributs OU
, mais pas les 2 autres. Quelqu'un pourrait-il vérifier le script et me dire ce qui ne va pas?Active Directory Copier les attributs utilisateur
Script:
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