Solved

Function to query AD group

Posted on 2011-03-04
3
418 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

734 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