You are viewing limited content. For full access, please sign in.

Question

Question

Workflow action: Query active directory

asked on January 24, 2018

What would be a setup for the Data Source in order to query Active Directory data?

0 0

Answer

SELECTED ANSWER
replied on January 24, 2018

Here is my solution:

I am using Custom Query, with Data Source being any of your SQL servers (it just needs an MSSQL platform to execute the query).

 

Here is my query that I use to get a list of employees, some of their basic information and their managers:

SELECT 
EmployeeID, 
Name, 
givenname, 
sn, 
mail, 
title, 
department, 
displayname,
REPLACE(SUBSTRING(manager,4,CHARINDEX(',OU=',manager) - 4),'\','') as manager
--this manager lookup was a bit tricky to setup but it works!

FROM OPENQUERY (ADSI,
'SELECT  
userAccountControl, 
manager, 
name, 
employeeID, 
department, 
mail, 
givenname, 
sn, 
title, 
displayname 

FROM ''LDAP://OU=YourOUgoesHere,DC=YourDCgoesHere,DC=YourDCgoesHere'' 
--You can find your LDAP information if you select any user in your AD environment and then look at the "distinguishedName" attribute, ignore the CN, and OUs depending on how many 'subfolders' you have.
WHERE objectCategory = ''Person'' AND objectClass = ''user''')
--The first Where statement is for AD to specify a user
WHERE employeeID <> 'NULL' and useraccountcontrol <> '66050' and title <> 'Vendor' and title not like '%Workstudy%'
--The second Where statement is for the data to exclude missing anything that isn't an employee in our environment
--The useraccountcontrol 66050 is eliminating disabled accounts
ORDER BY name

I truly hope that this helps someone, it works pretty well. You can always modify this report and have it select other columns by replacing the attributes in the SELECT statements. Whatever attribute you want to add, you have to select it in both SELECT statements otherwise you will get an "invalid column name" error.

Again, this can query to AD can be done against any SQL database!

1 0

Replies

replied on January 24, 2018

You will need to create a linked sever to AD.
@████████ just did a great write up on this  HERE a week or two ago.
Additionally google ADSI and Linked Server, there are dozens of articles.

Once that is setup you can query AD as if it were a normal database.

  Andrew

1 0
replied on January 24, 2018

Andrew, I just figured out a way to use a custom query in Workflow without having to setup an external database. See below if that helps you, but thank you for linking that!

0 0
replied on January 24, 2018

What are you trying to accomplish? Workflow already has support for Active Directory in the Find User/Group/Manager activities.

0 0
replied on January 24, 2018

I need to be able to write a value to a Notes field (attribute is info) in Active Directory using a Workflow (the actual value comes from a form). I wrote a query that works in SQL but I am not sure how to setup a data source.. I guess since my query is universal it will work on any SQL server data source - let me try that

0 0
replied on January 24, 2018

Looks like it will work from any SQL configured data source, against any database! I will post my solution

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.