Applescript to perform Active Directory query

I already have a VBScript which I am able to perform a ldap query and get the home folder value for users from Active Directory and them map to a drive letter in Windows. This users an account which is allowed to query all users in the directory.
I would like to do the same on the Apple Mac clients. I’ve already written a couple of AppleScripts to record system information to a MySQL database so I am a little familiar with the scripting language.

What I am after is some help on how to perform a ldap query against an Active Directory for which I have credentials that are allowed to query.
The clients that will run the script WILL NOT necessarily be bound to AD but may be stand alone on the network so I don’t want to use the local account credentials for the query.

Has anyone any suggestions or pointers?
Thanks in advance

Had the same issue (not bound to AD, etc)

ended up using ldapsearch:

set domainSTR to ""
set ouSTR to "ou=Employees,ou=Acme Users,dc=acme,dc=com"
set ldapQueryResults to ""
set UserPW to "Ru8815hP45sW0rd"
set UserID to "bob"

	set ldapQueryResults to do shell script "ldapsearch -H ldap:// -x -D " & UserID & "@" & domainSTR & " -w " & UserPW & " -b '" & ouSTR & "' -LLL sAMAccountName=" & UserID --
on error errMsg
	set ldapQueryResults to errMsg -- we do this so that the if statements below are neater and all use the same ldapQueryResults variable
end try

if ldapQueryResults contains "Invalid credentials (49)" then -- Bad credentials. UN / PW not entered correctly
	set CredCheck to "Incorrectly entered credentials. Please try again."
else if ldapQueryResults contains "Can't contact LDAP server" then -- server unreachable: are we connected to the network?
	set CredCheck to "Cannot contact server."
else if ldapQueryResults contains "distinguishedName" then -- success
	set CredCheck to "Success! Please click Continue..."
	set CredCheck to "There's been an undefined error. Please try again"
end if

log CredCheck

A documentation search of 10.8 returns nothing for ldap

Brilliant, thank you both for your quick replies. I will give this a go and post back my results.
Best wishes

There’s only one of me! :slight_smile:

Oh yeah :wink: