?
Solved

Sql server 2005 active directory users - distribution group

Posted on 2010-08-19
3
Medium Priority
?
540 Views
Last Modified: 2012-06-27
Hi All,
 
         I was able to pull the users from Active Directory into my sql server 2005 User table.
I followed http://blog.tech-cats.com/2007/09/querying-active-directory-through-sql.html

It successfully pulls user's generic information like  givenName ,sn ,displayName,  sAMAccountName,
telephoneNumber ,mobile , mail ,department,  physicalDeliveryOfficeName

The company I work for is distributed globally. Each country is located as a separate folder in active directory. When I pull user's into sql server table I would like to know which folder from active directory are they coming from in order for me to group users correctly based on country

Please help!!!
0
Comment
Question by:Hlobo
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
rscottvan earned 2000 total points
ID: 33486114
You'll need to grab the Distinguished Name (DN) which includes the AD path to the account.

Technically, what you're calling "folders" in AD are actually Organizational Units (OUs.)  

 A DN looks like this:
CN=<user name>, OU= <"folder">, OU=<"folder">,DC=<domain>,DC=<domain>

You'll have to parse out the OUs.

For example, if my account name was scott, and the tree was like this:
mydomain.com
--north america
----usa
------arizona
--------phoenix
----------scott
My DN would be:
CN=Scott,CN=users,OU=phoenix,OU=arizona,OU=usa,OU=north america,DC=mydomain,DC=com
0
 

Author Comment

by:Hlobo
ID: 33502239
Awesome ..Thank you so much rscottvan!
0
 

Author Comment

by:Hlobo
ID: 33532194
Hello All,

       I would like sql server 2005 script to get Get a list of users in a Distribution group

how would i do this?

I followed http://blog.tech-cats.com/2007/09/querying-active-directory-through-sql.html

but now I want users belonging to a security/distribution group
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

839 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