You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(attribute=value) # Basic equality
(&(attribute1=value1)(attribute2=value2)) # AND
(|(attribute1=value1)(attribute2=value2)) # OR
(!(attribute=value)) # NOT
(attribute:OID:=value) # Extended matching rule
PowerShell AD Module Commands
Basic User and Group Queries
# Get all usersGet-ADUser-Filter *# Get specific userGet-ADUser-Identity "username"# Get group membersGet-ADGroupMember-Identity "GroupName"# Find user in specific groupGet-ADGroupMember-Identity "DNSAdmins"# Get all properties of a userGet-ADUser-Identity "username"-Properties *# Get group informationGet-ADGroup-Identity "GroupName"
Using LDAP Filters in PowerShell
# Find disabled usersGet-ADObject-LDAPFilter '(&(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))'# Find users in specific OUGet-ADObject-SearchBase "OU=IT,OU=Employees,DC=DOMAIN,DC=LOCAL"-SearchScope SubTree -Filter "(objectCategory=Person)"# Find users with specific attributeGet-ADObject-LDAPFilter "(&(objectCategory=Person)(description=*))"# Count objects
(Get-ADObject-LDAPFilter '(objectClass=user)').Count
# Get specific propertiesGet-ADObject-LDAPFilter '(objectClass=user)'-Properties Name,Description | Select Name,Description
Common LDAP Filters
User Queries
(objectClass=user) # All users
(objectCategory=Person) # All people (slightly different from users)
(&(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2)) # Disabled users
(&(objectClass=user)(servicePrincipalName=*)) # Users with SPNs
(&(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=4194304)) # DONT_REQ_PREAUTH (ASREProastable)
(&(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=524288)) # TRUSTED_FOR_DELEGATION
(&(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=128)) # ENCRYPTED_TEXT_PWD_ALLOWED
(&(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=32)) # PASSWD_NOTREQD
(&(objectClass=user)(adminCount=1)) # Protected users (admins)
Computer Queries
(objectCategory=Computer) # All computers
(&(objectCategory=Computer)(userAccountControl:1.2.840.113556.1.4.803:=8192)) # Domain controllers
(&(objectCategory=Computer)(name=*WS*)) # Computers with name containing "WS"
Group Queries
(objectCategory=Group) # All groups
(&(objectCategory=Group)(adminCount=1)) # Admin groups
Nested Membership Queries
# Find groups a user is a member of (including nested groups)
(member:1.2.840.113556.1.4.1941:=CN=Username,OU=Users,DC=DOMAIN,DC=LOCAL)
# Find users who are members of a group (direct)
(memberOf=CN=GroupName,CN=Users,DC=DOMAIN,DC=LOCAL)
# Find all objects that are members of a group (including nested)
(memberOf:1.2.840.113556.1.4.1941:=CN=GroupName,CN=Users,DC=DOMAIN,DC=LOCAL)
# Find accounts requiring smartcard
(&(objectCategory=Person)(userAccountControl:1.2.840.113556.1.4.803:=262144))
# Find accounts with non-expiring passwords
(&(objectCategory=Person)(userAccountControl:1.2.840.113556.1.4.803:=65536))
# Find accounts with reversible encryption
(&(objectCategory=Person)(userAccountControl:1.2.840.113556.1.4.803:=128))
LDAP Search Scopes
# Search Scopes:# Base = 0 (just the OU itself, no members)# OneLevel = 1 (direct children only)# SubTree = 2 (all descendants)# Search only the specified OUGet-ADObject-SearchBase "OU=IT,OU=Employees,DC=DOMAIN,DC=LOCAL"-SearchScope Base -Filter *# Search direct children of the OUGet-ADObject-SearchBase "OU=IT,OU=Employees,DC=DOMAIN,DC=LOCAL"-SearchScope OneLevel -Filter *# Search the OU and all sub-OUsGet-ADObject-SearchBase "OU=IT,OU=Employees,DC=DOMAIN,DC=LOCAL"-SearchScope SubTree -Filter *# Count objects in an OU
(Get-ADObject-SearchBase "OU=IT,OU=Employees,DC=DOMAIN,DC=LOCAL"-SearchScope SubTree -Filter "(objectCategory=Person)").Count
Linux LDAP Tools
ldapsearch (OpenLDAP)
# Anonymous bind for public info
ldapsearch -x -H ldap://DOMAIN-CONTROLLER -b "DC=DOMAIN,DC=LOCAL""(objectClass=domain)"# Authenticated search
ldapsearch -x -H ldap://DOMAIN-CONTROLLER -b "DC=DOMAIN,DC=LOCAL" -D "CN=username,CN=Users,DC=DOMAIN,DC=LOCAL" -w 'password'"(objectClass=user)"# Find domain functional level
ldapsearch -x -H ldap://DOMAIN-CONTROLLER -b "DC=DOMAIN,DC=LOCAL""(objectClass=domain)" msDS-Behavior-Version
# Filter for specific attributes
ldapsearch -x -H ldap://DOMAIN-CONTROLLER -b "DC=DOMAIN,DC=LOCAL" -s base "(objectclass=*)" minPwdLength
# Find users with specific properties
ldapsearch -x -H ldap://DOMAIN-CONTROLLER -b "DC=DOMAIN,DC=LOCAL" -D "CN=username,CN=Users,DC=DOMAIN,DC=LOCAL" -w 'password' -s sub "(&(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=262144))" samaccountname
# Users with SPNs who are also in Protected Users groupGet-ADObject-LDAPFilter "(&(objectClass=User)(servicePrincipalName=*)(memberOf=CN=Protected Users,CN=Users,DC=DOMAIN,DC=LOCAL))"-Properties *
Finding Domain Information
# Domain policy info (password policy)Get-ADDefaultDomainPasswordPolicy# Domain functional level
(Get-ADDomain).DomainMode