Solved

Function to query AD group

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now