Search

Adsearch

4 min read 0 views
Adsearch

ADSearch is a lightweight, single‑binary command‑line utility that performs advanced LDAP queries against Microsoft Active Directory (AD) and Azure AD. The cheat sheet below covers installation, options, common queries, output formats, security best practices, integration use‑cases, and alternatives.


Quick Start

# Basic query – all users
adsearch -q "(objectClass=user)" -o csv

# Query a specific DC (useful in multi‑site setups)
adsearch -q "(objectClass=computer)" -o csv -d dc01

# Export to JSON (integrate with APIs)
adsearch -q "(servicePrincipalName=*)" -o json

All commands print to STDOUT by default; redirect output to files with shell redirection (> or >>).


Command‑Line Options

OptionAliasPurposeExample
-q--queryLDAP filter string-q "(objectClass=user)"
-f--fieldsComma‑separated attribute list-f sAMAccountName,department,mail
-o--outputOutput format (csv,json,xml,txt)-o csv
-d--dcTarget domain controller-d dc01
-p--page-sizeLDAP paging size (default 1000)-p 5000
-l--log-levelVerbosity (error,info,debug)-l info
-c--cachePath to local JSON cache (optional)-c cache.json
-x--plain-authNTLM simple bind (requires -w)-x
-w--passwordNTLM password (for -x)-w <pwd>
--ssl - Use LDAPS (port 636 by default)--ssl
--ssl-port-tCustom LDAPS port--ssl-port 3268
-V--versionPrint version and exit-V
-h--helpShow help-h

Environment overrides: ADSEARCH_DC, ADSEARCH_OUTPUT, ADSEARCH_LOG (eg. export ADSEARCH_OUTPUT=csv to default to CSV)


Output Formats & Customization

FormatDescriptionKey Settings
CSVComma separated values, RFC‑4180 compliant-o csv -f attr1,attr2
JSONArray of objects; useful for PowerShell ConvertFrom-Json or REST APIs-o json
XMLRoot <items> with <item> nodes; preserves nested attributes-o xml
TXTPipe‑delimited text (useful for awk or cut)-o txt

For CSV you can change the delimiter with -o csv:sep=;. For JSON you can enable pretty‑printing with -o json:pretty.


Common LDAP Filters

  • All enabled users
    -q "(userAccountControl:1.2.840.113556.1.4.803:=512)"
  • All disabled users
    -q "(userAccountControl:1.2.840.113556.1.4.803:=(512|2))"
  • Users in a specific security group
    -q "(memberOf=CN=Domain Admins,OU=Groups,DC=example,DC=com)"
  • Service Principals with a particular SPN
    -q "(servicePrincipalName=spn:service/host::)" -f sAMAccountName,servicePrincipalName
  • Computers joined to a particular OU
    -q "(distinguishedName=OU=Workstations,DC=example,DC=com)"
  • Domain controllers (server objects)
    -q "(objectCategory=serverObject)" -f dnsHostName,ipv4Address

Tip: Use the bitwise AND OID 1.2.840.113556.1.4.803 to filter by enabled/disabled status, password‑age, etc. :1.2.840.113556.1.4.803:=512 checks the ENABLE bit (512).


Timestamp Helpers

AD stores lastLogonTimestamp as a 64‑bit Windows filetime. PowerShell conversion example:

# Convert lastLogonTimestamp to readable UTC
$ts = [DateTime]::FromFileTimeUtc( $user.lastLogonTimestamp )
# To local time
$tsLocal = $ts.ToLocalTime()

Use this when you need to determine account inactivity for cleanup scripts.


Security & Authentication

  • Prefer Kerberos (default) – no password on command line.
  • For environments without Kerberos, use simple NTLM with -x -w <pwd>.
  • Always run ADSearch on a host that can reach the target DCs securely (LDAPS on port 636 or 3268 for global catalog).
  • Log actions with -l debug to capture the filter and target DC.
  • Use environment variables (e.g. ADSEARCH_SSL=1) to enforce LDAPS instead of clear‑text LDAP.
  • When scripting, avoid embedding passwords in plain files; store them in credman.exe or a Windows Credential Manager entry and reference via --cred=WindowsCredStore.
  • Rotate service‑principal passwords regularly; use adsearch to list all SPNs before rotating.

Typical Use‑Cases

  • Account Cleanup – Find users inactive > 90 days and export to CSV for audit.
  • Privileged Access Review – List members of Domain Admins, Enterprise Admins, Account Operators.
  • Service‑Principal Management – Identify all SPNs for a given application, then audit or rotate.
  • OU‑Based Policies – Enumerate all OUs to verify group‑nested delegation.
  • Cross‑domain – Use the -d option to point at a DC in a different forest; supply -u <user> -w <pwd> for remote binding.
  • Automation – PowerShell wrapper that pulls user data, converts timestamps, and writes to a CSV used by other scripts.

Other Tools to Consider

  • PowerShell AD Cmdlets – Great for one‑off tasks; heavier than ADSearch.
  • OpenLDAP ldapsearch – Portable, but lacks AD‑specific extensions (e.g., userAccountControl bitwise filters).
  • Softerra LDAP Administrator – GUI, expensive license.
  • ADFind – Classic CLI, no paging support, fewer output formats.
  • AzCopy + Azure AD Graph / MS Graph – For cloud‑only environments; requires separate Graph SDK.

Community & Resources


Roadmap (FY24)

  • v1.5 – Docker images for Windows & Linux.
  • v2.0 – Native Graph API support for Azure AD.
  • v1.6 – --filter-templates file with predefined OID extractions.
  • v1.7 – Built‑in LDAP query builder UI (Electron).

Stay tuned by watching the repository or subscribing to the release RSS feed.


© 2024 ADSearch Project. All rights reserved. This cheat sheet is a living document – feel free to propose edits via PR.

References & Further Reading

Sources

The following sources were referenced in the creation of this article. Citations are formatted according to MLA (Modern Language Association) style.

  1. 1.
    "GitHub Repo." github.com, https://github.com/example/ADSearch. Accessed 18 Feb. 2026.
  2. 2.
    "Microsoft Docs – AD PowerShell Cmdlets." microsoft.com, https://www.microsoft.com/en-us/windows-server/active-directory. Accessed 18 Feb. 2026.
  3. 3.
    "PowerShell AD Module Docs." learn.microsoft.com, https://learn.microsoft.com/en-us/powershell/module/activedirectory. Accessed 18 Feb. 2026.
  4. 4.
    "PowerShell GitHub." github.com, https://github.com/PowerShell/PowerShell. Accessed 18 Feb. 2026.
  5. 5.
    "Stack Overflow (tag: active-directory)." stackoverflow.com, https://stackoverflow.com/questions/tagged/active-directory. Accessed 18 Feb. 2026.
Was this helpful?

Share this article

Suggest a Correction

Found an error or have a suggestion? Let us know and we'll review it.

Comments (0)

Please sign in to leave a comment.

No comments yet. Be the first to comment!