Here is the code I am using to retrieve user information from AD. I do no know how to print this information to console. Please help me. Also do I need the setters and getters for this code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
namespace AD_Test.App_Start
{
public static class ADTest
{
public static String GetProperty(this Principal prici, String prop)
{
DirectoryEntry de = prici.GetUnderlyingObject() as DirectoryEntry;
if (de.Properties.Contains(prop))
return de.Properties[prop].Value.ToString();
else
return String.Empty;
}
public static String GetName(this Principal princi)
{
return princi.GetProperty("Full Name: ");
}
public static String GetBlazerID(this Principal principal)
{
return principal.GetProperty("BlazerID: ");
}
public static String GetDepartment(this Principal principal)
{
return principal.GetProperty("Department: ");
}
public static String GetEmail(this Principal pricipal)
{
return pricipal.GetProperty("Email: ");
}
public static String GetTitle(this Principal principal)
{
return principal.GetProperty("Title");
}
}
}