none
GAL Fields in Outlook. RRS feed

  • Question

  • Hi

    I have a code which fetches the details of the users (Alias, ManagerName) using Outlook Object. (Code snippet below).  The code works perfectly fine.  But I need to get the samAccountName property from the outlook object.  The property GetExchangeUser.Alias gets the Alias name which I saw is not always same as the samAccountName (Network Account Name).  Any help or pointers on this would be of great help.  Thanks in advance.

    -------------------------------------------------------------------------------------------------------------------------------------------

        ' Initialize a new instance of Outlook Application NOTE: Outlook needs to be open to be able to fetch the DL details
        Set oApp = New Outlook.Application
        Set oNS = oApp.GetNamespace("mapi")

        Set oDLs = oNS.AddressLists

        Set oGAL = oDLs.Item("All Groups")
            
        Set oEntries = oGAL.AddressEntries
        Set oDL = oEntries.Item(cDLName)

        cDLNameinOutlook = ReplaceString(oDL.Name, Space(1), "")
        cDLNameinOutlook = ReplaceString(cDLNameinOutlook, Chr(150), "")
        cDLNameinOutlook = ReplaceString(cDLNameinOutlook, Chr(45), "")
            
        cDLNameInDLM = ReplaceString(rst!FullDLName, Space(1), "")
        cDLNameInDLM = ReplaceString(cDLNameInDLM, Chr(150), "")
        cDLNameInDLM = ReplaceString(cDLNameInDLM, Chr(45), "")

         If cDLNameInDLM = cDLNameinOutlook Then

                ' Get all of the members of the distribution list.
                Set oMemberEntries = oDL.Members
                
                On Error GoTo EH_NotResolved

                ' Loop through each members in the DL
                For i = 1 To oMemberEntries.Count
                
                    On Error GoTo EH_Individual
                   
                    Set oEntry = oMemberEntries.Item(i)

                    cUserName = oEntry.Name
                    cLANID = Left(oEntry.GetExchangeUser.Alias, 20)
                    cEMail = oEntry.GetExchangeUser.PrimarySmtpAddress
                    cOffice = oEntry.GetExchangeUser.OfficeLocation

    Regards
    Ravi

    Saturday, March 22, 2014 1:00 PM

Answers

  • Hello Ravi,

    The article I mentioned above states the following:

    Generally speaking the Alias attribute will match a user’s sAMAccountName. This is not always the case. When Exchange is installed, the schema is extended, and a number of additional attributes are exposed. One of these attributes is ms-Exch-Mail-Nickname which maps to the LDAP attribute mailNickname within the collection of available Outlook LDAP attributes. It is normally populated when an account becomes mail-enabled with the user’s samAccountName. A mailNickname should be unique across an entire forest; a samAccountName only needs to be unique at the domain level. Additionally, if a user’s samAccountName is changed the mailNickName attribute is not automatically updated. In short, a casual glance through Outlook might suggest to the ususpecting administrator that the alias field maps to sAMAccountName – it does not. It maps to an exchange attribute known as mailNickname which more often than not resembles the contents of sAMAccountname.

    The Outlook object model doesn't expose such property. However, you may try to use any utility (for example, Outlook Spy) for exploring low-level properties provided by Extended MAPI.

    Sunday, March 23, 2014 10:39 AM

All replies

  • Hello Ravi,

    Please take a look at the User Account Attirbutes in AD: Part 1 Outlook LDAP Attributes article. It describes available AD attributes that Outlook object model provides via properties.

    Also you may find the VBA Outlook 2010 retrieving information from Active Directory forum thread helpful. It provides a sample code which retrieves the samAccountName attribute for a particular account.
    Saturday, March 22, 2014 1:38 PM
  • Hi Eugene

    Thanks for the pointers.  But this maps the outlook properties with LDAP properties.  I need the LDAP property equivalent of sAmAccountname in Outlook.  The Alias property is returning a value which is not always same as the sAmAccountname propery.

    Regards
    Ravi

    Sunday, March 23, 2014 2:05 AM
  • Hello Ravi,

    The article I mentioned above states the following:

    Generally speaking the Alias attribute will match a user’s sAMAccountName. This is not always the case. When Exchange is installed, the schema is extended, and a number of additional attributes are exposed. One of these attributes is ms-Exch-Mail-Nickname which maps to the LDAP attribute mailNickname within the collection of available Outlook LDAP attributes. It is normally populated when an account becomes mail-enabled with the user’s samAccountName. A mailNickname should be unique across an entire forest; a samAccountName only needs to be unique at the domain level. Additionally, if a user’s samAccountName is changed the mailNickName attribute is not automatically updated. In short, a casual glance through Outlook might suggest to the ususpecting administrator that the alias field maps to sAMAccountName – it does not. It maps to an exchange attribute known as mailNickname which more often than not resembles the contents of sAMAccountname.

    The Outlook object model doesn't expose such property. However, you may try to use any utility (for example, Outlook Spy) for exploring low-level properties provided by Extended MAPI.

    Sunday, March 23, 2014 10:39 AM