I am trying to get the list of all inactive members from a specific OU named inactive with the following queries:



(&(objectCategory=CN=Organizational-Unit,CN=Schema,CN=Configuration,DC=companyname,DC=com)(objectClass=organizationalUnit)(userAccountControl:1.2.840.113556.1.4.803:= OU=inactive,OU=Users,OU=Administration,DC=companyname,DC=com))

(&(objectCategory=CN=Organizational-Unit,CN=Schema,CN=Configuration,DC=companyname,DC=com)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:= OU=inactive,OU=Users,OU=Administration,DC=companyname,DC=com))

However the search is not returning any record.

The CN for the inactive OU is inactive/USERS/Administration/Companyname.

Whenever I give this path for the inactive OU it does not return any results.

Please let me know how can we get the required results. When I try searching it from the AD console it shows the results as there are 1350 users inactive, but I am trying to incorporate it in a script.

  • What are you trying to do exactly? Use powershell to return all the people in a specific OU? – Reaces Sep 1 '14 at 8:48

So you want to retrieve the members that are disabled in AD or not?

The disabled users in that ou:

Get-ADUser -Searchbase "OU=inactive,OU=Users,OU=Administration,DC=companyname,DC=com" -LDAPFilter "(!userAccountControl:1.2.840.113556.1.4.803:=2)"

The not-disabled users in that ou:

Get-ADUser -Searchbase "OU=inactive,OU=Users,OU=Administration,DC=companyname,DC=com" -LDAPFilter "(userAccountControl:1.2.840.113556.1.4.803:=2)"

Edit: Even if you are not using the ActiveDirectory-module, the .Net-methods also supports the .searchBase in the form of .searchRoot, but then you would probably need the LDAPfilter:

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.