Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PowerShell Connect to Oracle Internet Directory. Associated blogpost https://blog.darrenjrobinson.com/querying-oracle-internet-directory-ldap-with-powershell/
# Needs reference to .NET assembly used in the script.
Add-Type -AssemblyName System.DirectoryServices.Protocols
$username = 'cn=ldapUser'
$pwd = 'S3cur3P@$$W0rd'
$server = "ldap.customer.com.au"
$port = "80001"
$password = $pwd | ConvertTo-SecureString -asPlainText -Force
# Top Level OU under which users are located
$ldapSearchBase = "cn=users,dc=customer,dc=com,dc=au"
# Filter to find the user we are connecting with
$ldapSearchFilter = "(&(objectClass=Person)($($username)))"
# Username and Password
$ldapCredentials = New-Object System.Net.NetworkCredential($username,$password)
# Create a Connection
$ldapConnection = New-Object System.DirectoryServices.Protocols.LDAPConnection("$($server):$($port)",$ldapCredentials,"Basic")
# Connect and Search
$ldapTimeOut = new-timespan -Seconds 30
$ldapRequest = New-Object System.DirectoryServices.Protocols.SearchRequest($ldapSearchBase, $ldapSearchFilter, "OneLevel", $null)
$ldapResponse = $ldapConnection.SendRequest($ldapRequest, $ldapTimeOut)
$ldapResponse.Entries[0].Attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.