Created
June 20, 2025 13:23
-
-
Save lewebsimple/c6f23bad64e3a2aad9b8890f7dc6c766 to your computer and use it in GitHub Desktop.
Test LDAP credentials
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Tests LDAP credentials by attempting a bind. | |
.DESCRIPTION | |
This script prompts for LDAP server, username (Distinguished Name or UPN), and password. | |
It attempts to bind to the LDAP server and confirms success or failure. | |
.NOTES | |
Author: Your Name | |
Requires: Windows PowerShell with access to .NET DirectoryServices | |
#> | |
# Prompt for LDAP server and credentials | |
$ldapServer = Read-Host "Enter LDAP server (e.g., ldap://your-ldap-server or just hostname)" | |
$baseDN = Read-Host "Enter Base DN (e.g., dc=example,dc=com)" | |
$cred = Get-Credential -Message "Enter LDAP credentials" | |
# Compose LDAP path | |
$ldapPath = "LDAP://$ldapServer/$baseDN" | |
try { | |
# Create DirectoryEntry with credentials | |
$ldapEntry = New-Object System.DirectoryServices.DirectoryEntry($ldapPath, $cred.UserName, $cred.GetNetworkCredential().Password) | |
# Force bind by accessing a property | |
$null = $ldapEntry.NativeObject | |
Write-Host "`n✅ LDAP bind successful as '$($cred.UserName)'" -ForegroundColor Green | |
} | |
catch { | |
Write-Host "`n❌ LDAP bind failed:" -ForegroundColor Red | |
Write-Host $_.Exception.Message -ForegroundColor Yellow | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment