Storn
Storn

Reputation: 1

DirectorySearcher doesn't find locked users

I have the following problem. In my domain there are locked users. I am not able to query the locked user with the following code.

string ls_userfilter = "(SAMAccountName=" + myconfig.UserID + ")";

var ld_directory = new DirectoryEntry(myconfig.LDAPPath, null, null, 
    AuthenticationTypes.SecureSocketsLayer | AuthenticationTypes.Secure);

SearchResultCollection user;

try
{
    var searcher = new DirectorySearcher(ld_directory);
    searcher.Filter = ls_userfilter;
    searcher.SearchScope = SearchScope.Subtree;
    user = searcher.FindAll();
}

Via PowerShell and PrincipalContext I am able to get the user. I am not able to use PrincipalContext because of the authentication needed.

Any pointers are helpful.

I tried using GroupPrincipal. This is not feasible because of the Server configuration. As I understand it, the server is on LDAPS.

Upvotes: 0

Views: 45

Answers (1)

JD Thompson
JD Thompson

Reputation: 1

This works for me.

Search-ADAccount -lockedout -UsersOnly | select SamaccountName

Upvotes: 0

Related Questions