Last active
June 12, 2019 23:24
-
-
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/
This file contains 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
# 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