How can we programmatically access the user state in active directory? Especially state such as active/away/lockedout etc. This is to build a web snapshot to view all logged in users and their individual state.
So far, I could search all users under a specific domain but no luck in finding their current state.
using (var context = new PrincipalContext(ContextType.Domain, "domain"))
{
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
Console.WriteLine("First Name: " + de.Properties["givenName"].Value);
Console.WriteLine("Last Name : " + de.Properties["sn"].Value);
Console.WriteLine("User principal name: " + de.Properties["userPrincipalName"].Value);
}
}
}