Solved

Function to query AD group

Posted on 2011-03-04
3
408 Views
Last Modified: 2012-05-11
Does anyone have a function that i can use to determine if a specific user is a member of a specific ad group?

I'm going to pass a userid into a stored procedure and return one data set if a member of group 1 return another data set if a member of group 2.
0
Comment
Question by:gdspeare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Marten Rune earned 500 total points
ID: 35044355
SQL Server does not contain this information, but you can use is_member:
http://msdn.microsoft.com/en-us/library/ms186271.aspx

I e, SELECT is_member('domain\groupname')
Or:
If (SELECT is_member('domain\groupname')) = 1
BEGIN
  --T-SQL code to run when user is member of the domain group
END

//Marten
0
 

Author Comment

by:gdspeare
ID: 35058567
Thanks martenrune -

i was hoping that someone has done something cool....i"m actually handling this way....

is_member won't work by itself because often i'm not looking for the current user.
ALTER procedure [dbo].[usp_CheckDomainAdmin] 

  @vch_User		varchar(255)	= 'user',
  @int_Member	int				= 0	OUTPUT


AS

execute as login = @vch_User

set @int_Member = (SELECT is_member('utmsa\domain admins'))

declare @output int

exec usp_CheckDomainAdmin  
	@vch_User = 'utmsa\law777',
	@int_MEmber = @output output

print @output

Open in new window

0
 
LVL 20

Expert Comment

by:Marten Rune
ID: 35059070
This looks like it's going to work, but ...

does this mean your happy with the provided solution, or shall I come up with an alternative?

//Marten
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question