Richard Mueller said:
What is the format of you export file? For example, it could be:
manager1,report1
manager1,report2
manager1,report3
manager2,report4
or, perhaps:
manager1,report1,report2,report3
manager2,report4
Also, are all values Distinguished Names (DN's) or sAMAccountNames
(pre-Windows 2000 logon names)? Is the file comma delimited? If so and the
values are DN's, then the DN's must be enclosed in quotes.
A VBScript program can use the FileSystemObject to read the text file,
bind to each direct report user object, and assign the manager DN.
For example, if the text file is similar to (one typical line, watch line
wrapping):
"cn=Jim Smith,ou=West,dc=MyDomain,dc=com","cn=Roger
Wilson,ou=West,dc=MyDomain,dc=com","cn=Jane
Jones,ou=East,dc=MyDomain,dc=com"
where the first DN is that of the manager and the remaining DN's are direct
reports, then the VBScript program could be similar to below. Comma
delimited files can be difficult to read in VBScript, but the function used
below handles all situations.
==============
Option Explicit
Dim strFile, objFSO, objFile, strLine, strItem, strManager, objReport
Const ForReading = 1
' Specify the text file.
strFile = "c:\scripts\organization.csv"
' Open the text file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
' Read each line of the file.
Do Until objFile.AtEndOfStream
strLine = Trim(objFile.ReadLine)
' Skip blank lines.
If (strLine <> "") Then
' First determine the manager DN.
strManager = ""
For Each strItem In CSVParse(strLine)
' The first DN on the line is that of the manager.
If (strManager = "") Then
strManager = strItem
Else
' All subsequent DN's are of direct reports.
' Bind to direct report user object.
Set objReport = GetObject("LDAP://" & strItem)
' Assign manager DN.
objReport.manager = strManager
' Save changes.
objReport.SetInfo
End If
Next
End If
Loop
' Clean up.
objFile.Close
Function CSVParse(ByVal strLine)
' Function to parse comma delimited line and return array
' of field values.
Dim arrFields
Dim blnIgnore
Dim intFieldCount
Dim intCursor
Dim intStart
Dim strChar
Dim strValue
Const QUOTE = """"
Const QUOTE2 = """"""
' Check for empty string and return empty array.
If (Len(Trim(strLine)) = 0) then
CSVParse = Array()
Exit Function
End If
' Initialize.
blnIgnore = False
intFieldCount = 0
intStart = 1
arrFields = Array()
' Add "," to delimit the last field.
strLine = strLine & ","
' Walk the string.
For intCursor = 1 To Len(strLine)
' Get a character.
strChar = Mid(strLine, intCursor, 1)
Select Case strChar
Case QUOTE
' Toggle the ignore flag.
blnIgnore = Not blnIgnore
Case ","
If Not blnIgnore Then
' Add element to the array.
ReDim Preserve arrFields(intFieldCount)
' Makes sure the "field" has a non-zero length.
If (intCursor - intStart > 0) Then
' Extract the field value.
strValue = Mid(strLine, intStart, _
intCursor - intStart)
' If it's a quoted string, use Mid to
' remove outer quotes and replace inner
' doubled quotes with single.
If (Left(strValue, 1) = QUOTE) Then
arrFields(intFieldCount) = _
Replace(Mid(strValue, 2, _
Len(strValue) - 2), QUOTE2, QUOTE)
Else
arrFields(intFieldCount) = strValue
End If
Else
' An empty field is an empty array element.
arrFields(intFieldCount) = Empty
End If
' increment for next field.
intFieldCount = intFieldCount + 1
intStart = intCursor + 1
End If
End Select
Next
' Return the array.
CSVParse = arrFields
End Function