LDAP / Active Directory
Find users, test bind, Root DSE and LDAPS.
Find a user
Finds a user by sAMAccountName and shows core attributes (name, mail, DN, groups).
Active Directory
- LDAP server / DC
-
dc01.example.comChange in the builder → - Search base (Base DN)
-
DC=example,DC=comChange in the builder → - Username (sAMAccountName)
-
jdoeChange in the builder →
PowerShell (Windows)
DirectorySearcher (.NET) Built-in
$s = New-Object DirectoryServices.DirectorySearcher
$s.SearchRoot = "LDAP://dc01.example.com/DC=example,DC=com"
$s.Filter = "(sAMAccountName=jdoe)"
"displayName", "mail", "distinguishedName", "memberOf" | ForEach-Object { [void]$s.PropertiesToLoad.Add($_) }
$r = $s.FindOne()
if ($r) { $r.Properties } else { "not found" } ldapsearch Add-on tool
ldapsearch -x -H ldap://dc01.example.com -b "DC=example,DC=com" "(sAMAccountName=jdoe)" displayName mail distinguishedName memberOf Unix shell (bash)
ldapsearch Add-on tool
ldapsearch -x -H ldap://dc01.example.com -b "DC=example,DC=com" "(sAMAccountName=jdoe)" displayName mail distinguishedName memberOf curl Add-on tool
curl -s "ldap://dc01.example.com/DC=example,DC=com?displayName,mail?sub?(sAMAccountName=jdoe)" Without bind details the search runs as the signed-in Windows user (integrated auth). Linux has no built-in LDAP client: use ldapsearch (openldap-clients / ldap-utils) or curl with LDAP support; for ldapsearch add -D <bind DN> -W if needed.
Test bind / logon
Checks whether an account can bind (authenticate) to the directory.
- LDAP server / DC
-
dc01.example.comChange in the builder →
PowerShell (Windows)
DirectoryEntry (.NET) Built-in
$de = New-Object DirectoryServices.DirectoryEntry("LDAP://dc01.example.com", "CN=svc-ldap,OU=Service Accounts,DC=example,DC=com", "P@ssw0rd")
try { $null = $de.NativeObject; "bind ok: $($de.distinguishedName)" }
catch { "bind failed: $($_.Exception.Message)" } ldapsearch Add-on tool
ldapsearch -x -H ldap://dc01.example.com -D "CN=svc-ldap,OU=Service Accounts,DC=example,DC=com" -W -b "" -s base "(objectClass=*)" 1.1 Unix shell (bash)
ldapsearch Add-on tool
ldapsearch -x -H ldap://dc01.example.com -D "CN=svc-ldap,OU=Service Accounts,DC=example,DC=com" -W -b "" -s base "(objectClass=*)" 1.1 curl Add-on tool
curl -s -u "CN=svc-ldap,OU=Service Accounts,DC=example,DC=com:P@ssw0rd" "ldap://dc01.example.com/" Replace P@ssw0rd with the real password. -W in ldapsearch prompts for the password interactively.
Custom filter
Runs an LDAP search with a free-form filter and lists the matching DNs.
- LDAP server / DC
-
dc01.example.comChange in the builder → - Search base (Base DN)
-
DC=example,DC=comChange in the builder →
PowerShell (Windows)
DirectorySearcher (.NET) Built-in
$root = New-Object DirectoryServices.DirectoryEntry("LDAP://dc01.example.com/DC=example,DC=com", "CN=svc-ldap,OU=Service Accounts,DC=example,DC=com", "P@ssw0rd")
$s = New-Object DirectoryServices.DirectorySearcher($root, "(&(objectClass=user)(sAMAccountName=jdoe))")
$s.PageSize = 200
$s.FindAll() | ForEach-Object { $_.Properties["distinguishedname"] } ldapsearch Add-on tool
ldapsearch -x -H ldap://dc01.example.com -D "CN=svc-ldap,OU=Service Accounts,DC=example,DC=com" -W -b "DC=example,DC=com" "(&(objectClass=user)(sAMAccountName=jdoe))" dn Unix shell (bash)
ldapsearch Add-on tool
ldapsearch -x -H ldap://dc01.example.com -D "CN=svc-ldap,OU=Service Accounts,DC=example,DC=com" -W -b "DC=example,DC=com" "(&(objectClass=user)(sAMAccountName=jdoe))" dn curl Add-on tool
curl -s -u "CN=svc-ldap,OU=Service Accounts,DC=example,DC=com:P@ssw0rd" "ldap://dc01.example.com/DC=example,DC=com?dn?sub?(&(objectClass=user)(sAMAccountName=jdoe))" Replace P@ssw0rd with the real password. For an anonymous search, drop the bind part.
Root DSE
Reads the Root DSE: naming contexts, hostname and supported LDAP version, without authenticating.
- LDAP server / DC
-
dc01.example.comChange in the builder →
PowerShell (Windows)
[ADSI] RootDSE Built-in
$r = [ADSI]"LDAP://dc01.example.com/RootDSE"
$r.defaultNamingContext; $r.dnsHostName; $r.supportedLDAPVersion; $r.rootDomainNamingContext ldapsearch Add-on tool
ldapsearch -x -H ldap://dc01.example.com -s base -b "" "(objectClass=*)" + Unix shell (bash)
ldapsearch Add-on tool
ldapsearch -x -H ldap://dc01.example.com -s base -b "" "(objectClass=*)" + curl Add-on tool
curl -s "ldap://dc01.example.com/?+?base?(objectClass=*)" LDAPS (636)
Checks the encrypted LDAP connection and shows its certificate.
LDAPS (636)
- LDAP server / DC
-
dc01.example.comChange in the builder →
PowerShell (Windows)
SslStream (.NET) Built-in
$h = "dc01.example.com"; $p = 636
$c = New-Object Net.Sockets.TcpClient($h, $p)
$ssl = New-Object Net.Security.SslStream($c.GetStream(), $false, ({ $true }))
$ssl.AuthenticateAsClient($h)
([Security.Cryptography.X509Certificates.X509Certificate2]$ssl.RemoteCertificate) | Format-List Subject, Issuer, NotAfter
$ssl.Dispose(); $c.Close() ldapsearch Add-on tool
ldapsearch -x -H ldaps://dc01.example.com:636 -s base -b "" "(objectClass=*)" 1.1 Unix shell (bash)
openssl Built-in
openssl s_client -connect dc01.example.com:636 </dev/null 2>/dev/null | openssl x509 -noout -subject -dates ldapsearch Add-on tool
LDAPTLS_REQCERT=allow ldapsearch -x -H ldaps://dc01.example.com:636 -s base -b "" "(objectClass=*)" 1.1 Globaler Katalog (3269)
- LDAP server / DC
-
dc01.example.comChange in the builder →
PowerShell (Windows)
SslStream (.NET) Built-in
$h = "dc01.example.com"; $p = 3269
$c = New-Object Net.Sockets.TcpClient($h, $p)
$ssl = New-Object Net.Security.SslStream($c.GetStream(), $false, ({ $true }))
$ssl.AuthenticateAsClient($h)
([Security.Cryptography.X509Certificates.X509Certificate2]$ssl.RemoteCertificate) | Format-List Subject, Issuer, NotAfter
$ssl.Dispose(); $c.Close() ldapsearch Add-on tool
ldapsearch -x -H ldaps://dc01.example.com:3269 -s base -b "" "(objectClass=*)" 1.1 Unix shell (bash)
openssl Built-in
openssl s_client -connect dc01.example.com:3269 </dev/null 2>/dev/null | openssl x509 -noout -subject -dates ldapsearch Add-on tool
LDAPTLS_REQCERT=allow ldapsearch -x -H ldaps://dc01.example.com:3269 -s base -b "" "(objectClass=*)" 1.1 LDAPTLS_REQCERT=allow accepts an untrusted certificate too, so the test connection succeeds.