Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

Function to query AD group

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
gdspeare
Asked:
gdspeare
  • 2
1 Solution
 
Marten RuneCommented:
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
 
gdspeareAuthor Commented:
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
 
Marten RuneCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now