Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 get al users from active directory group

Author  Topic 

jimoomba
Yak Posting Veteran

90 Posts

Posted - 2013-01-04 : 05:33:35
Hi All,

I wanted to write a sql query to return all the users from a specific AD Group specifying the Group Name instead of the CN value in memberof.

I have written the query as shown below. kIndly help me on the same :

SELECT sAMAccountName as Login
FROM OPENQUERY( ADSI,
'SELECT sAMAccountname FROM ''LDAP:// DC=<<MyDomainName>>,DC=com''
WHERE objectCategory=''person'' AND objectClass=''user'' AND memberOf=''CN=<<MyGroupName>>,OU=BI,OU=Administrator Accounts,OU=MIS,OU=Corporate Users,DC=<<MyDomainName>>,DC=com''')

Kindly help me on the same

Thanks

rams

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-04 : 21:36:10
try like


SELECT
*
FROM OPENQUERY(ADSI,'<LDAP://DC=<<MyDomainName>>,DC=com>;(&(objectCategory=person)(objectClass=user)(memberOf=<<YourGroupName>>,OU=BI,OU=Administrator Accounts,OU=MIS,OU=Corporate Users,DC=<<MyDomainName>>,DC=com));cn,ADsPath;subtree')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -