I’m Brand new to LDAP Directory related works and seeking your help in fetching all Available LDAP Groups using PowerShell script.
LDAP Server: xxxx.domain.com:636 and have one service account.
Here is full script:
# Define the LDAPS server, port, and credentials
$ldapServer = "my-ldap-server"
$ldapPort = 636 # LDAPS port
$ldapPath = "LDAP://$ldapServer:$ldapPort"
$ldapUser = "your-username"
$ldapPassword = "your-password"
# Create a new DirectoryEntry object with the LDAPS path and credentials
$directoryEntry = New-Object System.DirectoryServices.DirectoryEntry
$directoryEntry.Path = $ldapPath
$directoryEntry.Username = $ldapUser
$directoryEntry.Password = $ldapPassword
$directoryEntry.AuthenticationType = [System.DirectoryServices.AuthenticationTypes]::SecureSocketsLayer
# Create a new DirectorySearcher object
$directorySearcher = New-Object System.DirectoryServices.DirectorySearcher($directoryEntry)
# Define the filter to search for groups
$directorySearcher.Filter = "(objectClass=group)"
# Define the properties to load (e.g., group name, description)
$directorySearcher.PropertiesToLoad.Add("cn")
$directorySearcher.PropertiesToLoad.Add("description")
# Perform the search
$searchResults = $directorySearcher.FindAll()
# Loop through the results and display group information
foreach ($result in $searchResults) {
$groupName = $result.Properties["cn"] -join ", "
$groupDescription = $result.Properties["description"] -join ", "
Write-Output "Group Name: $groupName"
Write-Output "Description: $groupDescription"
Write-Output "-------------------------"
}
# Clean up
$directorySearcher.Dispose()
$directoryEntry.Dispose()
I was able to verify test-connection and found 200 Status for the same. But i was not able to query for LDAP Groups. Can anyone of you help me in this regard.
Thanks in Advance.
Thanks,
Siva