laserpp

Distinguished
Nov 29, 2008
137
0
18,630
Alright had another thread but closed it to make a fresh one.

I have multiple problems but going to take them on 1 at a time. First problem I am accessing my Active Directory and producing all the CN (user names). I want to also produce their email addresses(MAIL). For some reason when pulling in the data from the AD it is only bringing in 32 fields out of the like 60-70 each user has(and of course MAIL isn't one of them). Does anyone know why it isn't pulling in all the properties?

Here's the code
Code:
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
using Microsoft.Office.Interop.Excel;
using System.DirectoryServices.ActiveDirectory; 


namespace EmailListing
{
    class Program
    {
        static void Main(string[] args)
        {
          
            
            
            DirectoryEntry adFolderObject = new DirectoryEntry("LDAP://OU=PHF Users,DC=phf,DC=inc");
            DirectorySearcher adSearchObject = new DirectorySearcher(adFolderObject);
            adSearchObject.SearchScope = SearchScope.Subtree;
            
                                 

            adSearchObject.Filter = "(&(ObjectClass=user)(!description=Built-in*))";

           


            foreach (SearchResult adObject in adSearchObject.FindAll())
             {
                Console.Write(adObject.Properties["cn"][0]); 
                Console.Write(".");
                Console.WriteLine(adObject.Properties["countryCode"][0]); //Just using countryCode bc I saw it was listed as one of the properties pulled in
                
               
               
             }

            Console.WriteLine();
            Console.ReadLine();
        }
    }
}
 
Solution
I have no idea. As I said this is beyond my expertise. I just thought the number of 32 was interesting considering there are more than double that available and that nothing "just happens" in the world of coding. Things only happen when code says to do so.

randomizer

Distinguished
I'm not particularly familiar with the AD-related classes, but you may need to add "mail" to adSearchObject.PropertiesToLoad (see http://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher.propertiestoload.aspx)
 

majestic1805

Honorable
Oct 1, 2012
69
0
10,590
Have you tried looking to see if 32 fields is some sort of built-in limitation? Perhaps you need to trim some off in order to bring in new ones. I just ask as 32 is a nice 2^x (5 in this case) number in classic computer tradition and could see some enterprising developer thinking that's *got* to be more than enough. This is well within the bounds of even a 16 bit integer but it's an interesting anecdote to me.
 

laserpp

Distinguished
Nov 29, 2008
137
0
18,630
Interesting, didn't think about that, I will look into that, the thing is the 32 fields are like spread all over the users account, it isnt like the first 32 fields which I would think is wierd if it did limit to only 32 fields. If that was the case wouldn't it just pick the first 32 fields
 

majestic1805

Honorable
Oct 1, 2012
69
0
10,590
I have no idea. As I said this is beyond my expertise. I just thought the number of 32 was interesting considering there are more than double that available and that nothing "just happens" in the world of coding. Things only happen when code says to do so.
 
Solution