Re: How to import hierarchy data into AD
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 24 Mar 2009 16:31:26 -0500
"Marcus" <Marcus@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:EE46CC4B-0CD5-480B-A08D-5A91EC16A5E9@xxxxxxxxxxxxxxxx
Great!
My file would be like this:
Manager; Report 1; Report 2;
Is it possible to use the User ID (Pre-Windows 2000) instead of the DN?
You can use the NameTranslate object to convert pre-Windows 2000 names to
DN's. Also with semicolon delimiters it will be much easier to parse each
line, assuming no values have embedded semicolons. My earlier program
becomes:
============
Option Explicit
Dim strFile, objFSO, objFile, strLine, strItem, strManager, objReport
Dim objTrans, strNetBIOSDomain, objRootDSE, strDNSDomain, strReport
Dim arrValues
Const ForReading = 1
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
' Specify the text file.
strFile = "c:\scripts\organization.csv"
' Determine DNS name of domain from RootDSE.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)
' 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 = ""
arrValues = Split(strLine, ";")
For Each strItem In arrValues
' The first DN on the line is that of the manager.
If (strManager = "") Then
' Use the Set method to specify the NT format of the manager
name.
' Trap error if user does not exist.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" &
strItem
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Manager " & strItem & " not found."
' No need to deal with reports if manager unknown.
Exit For
Else
On Error GoTo 0
' Use the Get method to retrieve the RPC 1779
Distinguished Name.
strManager = objTrans.Get(ADS_NAME_TYPE_1779)
End If
Else
' All subsequent DN's are of direct reports.
' Use the Set method to specify the NT format of the
report's name.
' Trap error if user does not exist.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" &
strItem
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Direct report " & strItem & " not found."
Else
On Error GoTo 0
' Use the Get method to retrieve the RPC 1779
Distinguished Name.
strReport = objTrans.Get(ADS_NAME_TYPE_1779)
' Bind to direct report user object.
Set objReport = GetObject("LDAP://" & strReport)
' Assign manager DN.
objReport.manager = strManager
' Save changes.
objReport.SetInfo
End If
End If
Next
End If
Loop
' Clean up.
objFile.Close
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
.
- References:
- How to import hierarchy data into AD
- From: Marcus
- Re: How to import hierarchy data into AD
- From: Richard Mueller [MVP]
- Re: How to import hierarchy data into AD
- From: Marcus
- How to import hierarchy data into AD
- Prev by Date: Re: How to import hierarchy data into AD
- Next by Date: Re: RRAS - required as Internet Gateway
- Previous by thread: Re: How to import hierarchy data into AD
- Next by thread: Re: RRAS - required as Internet Gateway
- Index(es):
Relevant Pages
|