Get AD group's member IDs

I am trying to come up with a sql server script that will list IDs and their level of access. I have done the part where t checks for all Logins on the SQL Server and database user. But a lot of these logins are actually Windows AD groups and not individual IDs. Is there a way that I can pass the groupID to a bat file and the bat file checks if its a group and returns all the IDs that are a part of that group?

Many thanks,
Who is Participating?
BodestoneConnect With a Mentor Commented:
Try the following. It should return all the AD members of the SQL login if that login is a group

xp_logininfo @acctname = 'mySQLLogin',
   @option = 'members'
BodestoneConnect With a Mentor Commented:
Did you have any luck with that by the way? If you need to do more complex queries on it you can put it in a temp table and run scripts from there:

INSERT #groupInfo
exec xp_logininfo @acctname = 'mySQLLogin', @option = 'members'

SELECT * FROM #groupInfo
--and the other stuff you need to do

DROP TABLE #groupInfo
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.