Count AD disabled accounts C#
Posted on 2011-03-14
I'm using system.directoryservices.accountmanagment and c# I'm trying to programmatically count the number of disabled accounts on the network.
Here is the part of the code that I'm using to get that those numbers.
int count = 0;
UserPrincipal u = new UserPrincipal(ctx);
PrincipalSearcher s = new PrincipalSearcher();
s.QueryFilter = u;
foreach(Principal p in u.FindAll())
if(u.Enabled == false)
// then I gon on to display count
Problem is that it always displays 0. Please help. Thanks. I eventually want to be able to programmatically find the number of lockedaccounts as well.