Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active June 12, 2019 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/b6818a136efe6dbf52e112ea58160842 to your computer and use it in GitHub Desktop.
Save darrenjrobinson/b6818a136efe6dbf52e112ea58160842 to your computer and use it in GitHub Desktop.
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