Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NameTranslate Issues

Status
Not open for further replies.

djtech2k

MIS
Jul 24, 2003
1,097
US
I am having to use nametranslate to transform a displayname and output samaccountname in active directory.

My issue is that the environment has a trust with other forests/domains so when i search for a displayName, it finds more than one instance and nametranslate fails.

Is there any way to force nametranslate to ONLY search one domain? I tried this:

Code:
	Set objTrans = CreateObject("NameTranslate")
	objTrans.Init ADS_NAME_INITTYPE_GC, "domain.com"
	objTrans.Set ADS_NAME_TYPE_DISPLAY, person
	strUserName = objTrans.Get(ADS_NAME_TYPE_NT4)

This still finds the result from the other forest and dies. Any idea how to get around this and only search one domain?

 
Can't you get something a little more concrete, like Distinguished Name or SMTP address?

Or maybe you can guarantee that the display names are from the current domain? That will give you the ability to use ADSI instead.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
I wish it were that simple.

Here is the objective:

Because of DST issues with Exchange/Outlook, this environment has instances where someone arranges a meeting in outlook but the time that the meeting starts differs from the organizer to the attendees. So, I have to come up with a process to identify all meetings where the organizers calendar is different that the attendees calendar.

So I have some of it done. I am now enumerating all appointments based on Exchange server. I enumerate all the appointments and in order to look for the mismatch, I have to then enumerate all of the meetings on each attendees calendar to find a match. So, the first result set gives me the appointment data and the attendees. In the second "loop" I need to grab each attendee and go to their calendar much in the same way. The problem is that the data I get in the first result set is something like "Lastname, Firstname" and I need to flip that into sAMAccountName. The only REAL match I can find is displayName.

Does that make sense? In the end, Exchange is only giving me "lastname, firstname" so I need a way to take that format and get sAMAccountName back.

I am looking for a good way to do this that will be realistic. I have thought of doing some kind of ADO search, but I am trying not to do that because of complexity and length.

I will post the script here. Please keep in mind that it is very sloppy right now as it is in a very "debug" state as I have been trying to figure out all the breaking points. The functions are also very ugly as well, but the requirements have changed a few times along the way and I have had to adapt on-the-fly and quickly.

Any suggestions are welcomed and a solution is greatly appreciated :).

Code:
Option Explicit
Dim strBase, strComputerName, strAttrs, strScope
Dim theServer, theSG, theConn, sg, mailDB, strUserName
Dim objRS, strMailBox, i, strUser, u, strDN
Dim person, arrAttendees, objTrans
Dim strSubject, strOrg, strBody
Const CdoDefaultFolderCalendar = 0
Const ADS_NAME_TYPE_1779 = 1
Const ADS_NAME_TYPE_CANONICAL = 2
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_DISPLAY = 4
Const ADS_NAME_TYPE_DOMAIN_SIMPLE = 5
Const ADS_NAME_TYPE_ENTERPRISE_SIMPLE = 6
Const ADS_NAME_TYPE_GUID = 7
Const ADS_NAME_TYPE_UNKNOWN = 8
Const ADS_NAME_TYPE_USER_PRINCIPAL_NAME = 9
Const ADS_NAME_TYPE_CANONICAL_EX = 10
Const ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME = 11
Const ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME = 12

'On Error Resume Next

'------ CONFIG ------
 strBase = "<LDAP://DC.Domain.com>;"
 strComputerName = "Exchange.Domain.com"
 strAttrs = "cn,sAMAccountName;"
 strScope = "subtree"
 u = 0
'------ END CONFIG ----
 
  Set theServer = CreateObject("CDOEXM.ExchangeServer")
  Set theSG = CreateObject("CDOEXM.StorageGroup")
  Set theConn = CreateObject("ADODB.Connection")
  theConn.Open "Provider=ADsDSOObject;"
 
  theServer.DataSource.Open strComputerName


  ' look at all storage groups for mailboxes
  ' strComputerName is Exchange Server
  ' strMailBox is username
  ' strUser is cn
   For Each sg In theServer.StorageGroups
      WScript.Echo "Storage group " & Chr(34) & sg & Chr(34)
      theSG.DataSource.open sg
      i = 0
      For Each mailDB In theSG.MailboxStoreDBs
        i = i+1
        WScript.Echo "  Mailbox database " & i & ": " & mailDB & vbcrlf
        'wscript.Echo "      Users: "
	    Set objRS = theConn.Execute(strBase & "(&(homeMDB=" & mailDB & ")(sAMAccountName=*)(!mail=*system*));"  & strAttrs & strScope)
 
 		objRS.MoveFirst
 		While Not objRS.EOF And ObjRS.RecordCount > 0
		u = u + 1
			strUser = objRS.Fields(0).Value
   			strMailBox = objRS.Fields(1).Value
		
			CALL GetApptData(strComputerName,strMailBox,strUser)
			strMailBox = ""
   			objRS.MoveNext
 		Wend   
 		'wscript.echo Chr(13) & Chr(13)    
      Next 
   Next

Function GetApptData(strComputerName,strMailBox,strUser)
Dim objSession, strProfileInfo, objAppointment, strAttendees, Attendee
Dim objAppointmentItems, objFolder
strProfileInfo = strComputerName & vbLf & strMailBox

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, True, 0, True, strProfileInfo
strMailBox = ""

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderCalendar)

' Get all Appointment Items
Set objAppointmentItems = objFolder.Messages

' Loop through the AppointmentItems collection
For Each objAppointment In objAppointmentItems
  
  For Each Attendee In objAppointment.Recipients
  strAttendees = strAttendees & " ; " & Attendee
  Next

  ' Display data for each appointment
  If objAppointment.IsRecurring = True And strAttendees <> "" Then
	wscript.echo "############NEW USER###################################" & vbcrlf
	wscript.echo strUser & ";" & objAppointment.Subject & ";" & objAppointment.StartTime & ";" & objAppointment.EndTime & ";" & objAppointment.Organizer & strAttendees
wscript.echo "AFTER OUTPUT>>>>>>>>>>>>>>>>>>  " & strAttendees
	arrAttendees = Split(strAttendees," ; ")
	For Each person In arrAttendees
	wscript.echo "PERSON:   " & person
	wscript.echo "AFTER PERSON>>>>>"
	Set objTrans = CreateObject("NameTranslate")
	objTrans.Init ADS_NAME_INITTYPE_GC, ""
	objTrans.Set ADS_NAME_TYPE_DISPLAY, person
	strUserName = objTrans.Get(ADS_NAME_TYPE_NT4)

	'wscript.echo "###############################################" & vbcrlf
	strSubject = objAppointment.Subject
	strOrg = objAppointment.Organizer
	strBody = objAppointment.Body

	CALL GetApptData2(CdoDefaultFolderCalendar,strComputerName,strUserName,person,strSubject,strOrg,strBody)
	Next
  End If
strAttendees = ""  
Next

'Clean Up
objSession.Logoff
Set objSession = Nothing
End Function

Function GetApptData2(CdoDefaultFolderCalendar,strComputerName,strUserName,person,strSubject,strOrg,strBody)
Dim objSession2, strProfileInfo2, objAppointment2, strAttendees2, Attendee2
Dim objAppointmentItems2, objFolder2
strProfileInfo2 = strComputerName & vbLf & strUserName
wscript.echo "11111111111111"

Set objSession2 = CreateObject("MAPI.Session")
objSession2.Logon "", "", False, True, 0, True, strProfileInfo2
strUserName = ""

Set objFolder2 = objSession2.GetDefaultFolder(CdoDefaultFolderCalendar)
wscript.echo "2222222222222222222"
' Get all Appointment Items
Set objAppointmentItems2 = objFolder2.Messages

' Loop through the AppointmentItems collection
For Each objAppointment2 In objAppointmentItems2
  wscript.echo "33333333333333333333333"
  For Each Attendee2 In objAppointment2.Recipients
  strAttendees2 = strAttendees2 & " ; " & Attendee2
  wscript.echo "4444444444444444444444444444"
  Next

  ' Display data for each appointment
  If strSubject = objAppointment2.Subject And strOrg = objAppointment2.Organizer And strBody = objAppointment2.Body Then
  wscript.echo "555555555555555555555555555555"
	wscript.echo vbtab & "Attendee Data: " & person2 & ";" & objAppointment2.Subject & ";" & objAppointment2.StartTime & ";" & objAppointment2.EndTime & ";" & objAppointment2.Organizer & strAttendees2
wscript.echo "666666666666666666666666666666666666"
End If
strAttendees2 = ""  
Next

'Clean Up
objSession2.Logoff
Set objSession2 = Nothing
End Function

wscript.echo "Total User Count: " & u
 
I may have found a way, but cannot get it test until tomorrow. Instead of looking for the GC, I think I can limit the nametranslate to a domain, which is what I need to do if I have to use displayName. The dupes are in other domains mostly. displayName is the only option I can find as of yet...

Anyway, here is the line that may at least help me a little, although its not a solution:

Code:
Const ADS_NAME_INITTYPE_DOMAIN = 1
objTrans.Init ADS_NAME_INITTYPE_DOMAIN, "domain.com"
 
About line 86 you have:
strAttendees = strAttendees & " ; " & Attendee

Take a look at "Attendee.Address"

That may yield to you something pretty close to the user's sAMAccountName.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Will do. I have to string the attendee list together in order to echo it out in the report, so that's whats up with that line. I thought the address was something to do with location for the meeting, eg 123 Main Street.
 
Ok, so i tried the

objTrans.Init ADS_NAME_INITTYPE_DOMAIN, "domain.com"

and it resulted with the same thing....says more than one value and errors. Thats even though the other user is in a different forest/domain.

Anyway, so I am back to the beginning on this.
 
Take a look at the attendee.address one more time. You may be able to strip down the result to give you the CN of the user which you can use for another ADO query of AD.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
I cannot touch the environment this minute so could you give me a hint as to what type of data it pulls or what field it links to?
 
Still dont have access....what does attendee.address give you? I mean type of value is it?
 
Here's the test code based on your code:

Code:
Dim objSession, objAppointment, strAttendees, Attendee
Dim objAppointmentItems, objFolder

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, True, 0, True, "exchclust-la02p.corp.tcw.com" & vbLf & "chapmp"

Set objFolder = objSession.GetDefaultFolder(0)

' Get all Appointment Items
Set objAppointmentItems = objFolder.Messages

' Loop through the AppointmentItems collection
For Each objAppointment In objAppointmentItems
  
	For Each Attendee In objAppointment.Recipients
		WScript.Echo Attendee.Address
	Next
Next

This code yields:
EX:/O=ORGNAME/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=JDOE
User in Exchange Organization
Equivalent AD attribute: legacyExchangeDN


SMTP:bob@somedomain.com
User outside Exchange Org

EX:/O=NT5/ou=E599226552771341ACB86D5368CF9D58/cn=0034E5A6625EC34EB2018B026C5E9B04
Unknown user (i.e. I don't know what it is. It appears that the user has been removed from the system)

The first one you should be able to look up in AD. I don't know if the legacyExchangeDN is searchable, but it does end with the CN of the user, which should be searchable.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
So attendee.address returns the legacyexchangeDN? Whats the bob@...? Is that a representative of one thats a user from another org/domain so it returns the smtp address?

Thanks. If this is true in this environment, then an ADO search should work much better...but I am now having a problem with even a basic ADO search. I have another thread about that. For some reason, it will allow me to echo the recordset.recordcount, but when I get into the "Do Until...EOF" part, it acts as if its not there. I have done that hundreds of times in all kinds of environments, but this one does not like it for some reason.

I will be glad when I get this one DONE!
 
BTW, legacyexchangedn IS searchable in AD. I have used it before when doing data analysis/reporting between a BlackBerry BES server and Exchange/AD.
 
How many users would you say there are total across all the domains?

If the number isn't too extremely high...I would probably query each domain and build a text file with the displayname and corresponding samaccountname....load this association into a dictionary...as you loop through each users displayname...you can easily access their samaccountname from the dictionary if it exists...

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I don't know at this point, BUT I only need data from 1 domain. The others do not matter to me. The point is to identify any instances where the meeting tie is different between the attendee and organizers calendar.

So I attach to exchange and enumerate the appointment data. The only way I can check the attendee's calendar that I can find is to loop thru each attendee's mailbox/calendar and match it to the one I am searching at that moment. As for the match, I cannot find a unique value so I am having to use the subject, organizer, etc. It sucks, but its all I can find. Anyway, to attach to the attendee calendar, I need his username. Well, the attendee data that I get is in the format of displayName. So I need to take displayName and somehow get the username form it. Problem is there can be multiple of the same displayName.

So my numerous challenges are:

1) Find unique field to link appointment from organizer to attendee's calendar.

2) Get unique attendee data that can help me find the username (trying legacyExchangeDN next).

3) Get the nametranslate or ADO query to get the attendee username to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top