I have googled how to list locked out accounts and found two methods so far, both of which don't work...
Saved query - (&(&(&(objectCategory=Person)(objectClass=User)(lockoutTime>=1))))
Lists a number of accounts, many of which are not locked out. If I unlock one that I happen to know is locked out, it still gets returned by the query.
Powershell command - Search-ADAccount -LockedOut
Does nothing.
So either - Am I doing something wrong? Or - Is there a method that actually works?
I would not necessarily trust
Get-ADUser -LDAPFilter "(&(objectCategory=Person)(objectClass=User)(lockoutTime>=1))" -Properties LockedOut
, as it is not returning reliable results for me either, but then, I'm also unable to directly contact my PDCe at this time. For best results, you would want to directly target your PDC-emulator, as it always has the most up-to-date information on account lockouts throughout the domain.That's what I am wagering that you're witnessing here is a delay in replication:
So try
Search-ADAccount -LockedOut -Server DC-PDCE
and see if your results are any better.Also, here's something else to consider when building queries around the lockoutTime attribute:
Edit: By way of reverse engineering
Microsoft.ActiveDirectory.Management.dll
, I can tell you thatSearch-ADAccount -LockedOut
, which seems to me to produce pretty reliable results, runs the following code:So it appears that
Search-ADAccount -LockedOut
is looking at the AccountLockoutTime attribute too!Edit some more for great justice: Richard Mueller, Dir. Services MVP, says this:
I can verify this thusly:
Finally, I'd like to end on this blog post on the topic, which explains why the
lockoutTime>=1
is approaching the best solution, but that's only part of the story. You need to further filter down the list to include only the users where their lockoutTime is greater than $(your domain lockout duration) minutes in the past.