Tom Mikinley February 2016

C# Active Directory - Query Unsuccessful Login Attempts

Is there a way to return a list of Active Directory login attempts using C#? For example, I would like to somehow return a list that contains the following

  • DC Name
  • Site
  • User State
  • Bad Pwd Count
  • Last Bad Pwd
  • PWD Last Set
  • Lockout Time

Essentially, I would like to know which device that is accessing Active Directory is causing a password lockout, on password updates.

I have looked at using the UserPrincipal class in System.DirectoryServices.AccountManagement but I cannot find a method that allows one to aggregate across DCs.

Thanks in advance for any help or advice!

Answers


Tomas Nilsson February 2016

There's no built in support for aggregating across multiple DCs. You have to handle that manually. This might get you started - this code will give you all domain controllers. Note - if you run this on a computer outside of the domain, it will throw an exception.

foreach (var l_DomainController in Domain.GetCurrentDomain().DomainControllers)
{
    Console.WriteLine(l_DomainController.ToString());
}

Post Status

Asked in February 2016
Viewed 1,385 times
Voted 11
Answered 1 times

Search




Leave an answer