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
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();
}
}
}