Skip to content
Advertisement

SQL query to run LDAP query to return AD listing of active users and then groups they are assigned to that start with GRP-XP%

I am trying to write a sql statement to control a report header selection of multiple database by user groups a user is assigned to. This is to limit the database selection security when running an SSRS report so that they can’ only select their branch or group of branches they have access to. So far I can return the group results for a single user. I am trying to get a list of all active AD users and groups that are like GRP-XP%. Here is my script so far, that only works for a single username. Eventually this table will be passed to PowerBI, so I’d need username, usergroup table of listing complete.

So the results would look like;

enter image description here

Thank you

Advertisement

Answer

I found some code I wrote many years ago. I can’t test it as we no longer use a local AD domain controller but it definitely worked at some point.

It basically returns a list of all users and associated groups so it should be easy enough to modify for your needs.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement