+ Reply to Thread
Results 1 to 18 of 18

Active Directory Data Using Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Active Directory Data Using Macro

    Hi Everyone,
    Looking for help (again) ^^
    Been doing some search here and there looking for a good solution to extract information/data on our Active directory.
    Basically what i want to do is to be able to pull up all the members of groups on my AD.
    Say I will just put the group name on one cell and when I run a Macro, it will return the AD Group list of users on another column.
    I'm sure this is possible, Im just not sure how it can be done.
    Hope someone out there could help or lead me to the right direction.

    Many thanks,
    Vince
    Last edited by romperstomper; 11-08-2010 at 03:34 AM. Reason: mark solved

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Active Directory Data Using Macro

    Here's a sample sub for copying the users in a specified group to a worksheet (output from A2):
    Sub GetGroupList(strGroup As String)
       On Error Resume Next
       Dim objConnection, objCommand, objRecordset, objRoot, strDomain
       Const ADS_SCOPE_SUBTREE = 2
       Set objRoot = GetObject("LDAP://rootDSE")
       'Work in the default domain
       strDomain = objRoot.Get("defaultNamingContext")
       
       Set objConnection = CreateObject("ADODB.Connection")
       Set objCommand = CreateObject("ADODB.Command")
       objConnection.Provider = "ADsDSOObject"
       objConnection.Open "Active Directory Provider"
       Set objCommand.ActiveConnection = objConnection
       
       objCommand.Properties("Page Size") = 1000
       objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
       
       objCommand.CommandText = _
          "SELECT SAMAccountName FROM 'LDAP://" & strDomain & _
              "' WHERE objectClass='user' And groupName = '" & strGroup & "' ORDER BY SAMAccountName"
       Set objRecordset = objCommand.Execute
       
       objRecordset.MoveFirst
       If Not objRecordset.EOF Then ActiveSheet.Cells(2, 1).CopyFromRecordset objRecordset
       objRecordset.Close
       objConnection.Close
    End Sub
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro

    Hi everyone,
    Thank's for the feedback.
    What i really wanted to achieve is described on the image below.
    I hope somebody will be able to help as I'm very desperate.


    Thank you in advance ^^
    Last edited by Vincent.Eymard; 10-31-2010 at 11:42 PM.

  4. #4
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,375

    Re: Active Directory Data Using Macro

    please use the forum tools to upload files. Untrusted external websites are not welcome for file uploads, especially since many are blocked by corporate firewalls.

  5. #5
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro

    Hi,
    Apologies, I didn't know I can make attachments using thread tools.
    Just the same i have rectified.
    Hope someone can help. Thanks very much.

    Vincent
    Attached Images Attached Images

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Active Directory Data Using Macro

    You have attached a picture, why not attach a sample workbook so somebody can work with it.

  7. #7
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro

    Quote Originally Posted by davesexcel View Post
    You have attached a picture, why not attach a sample workbook so somebody can work with it.
    Hi Dave,
    Thanks, I have attached the Excel sheet. Hope I did it correctly this time.
    And I hope somebody out there will be able to help.
    Thanks again ^^

    Vince
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro

    I hope somebody would be able to help

    Thank you in advance..

  9. #9
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro

    Still no luck
    Hope someone could help or maybe direct me where I could get an answer..

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Active Directory Data Using Macro

    I already gave you sample code, but you appeared to ignore it.
    Attached Files Attached Files
    Last edited by romperstomper; 11-04-2010 at 05:00 AM. Reason: add file

  11. #11
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro

    Quote Originally Posted by romperstomper View Post
    I already gave you sample code, but you appeared to ignore it.
    @romperstomper
    Hi! Apologies, I didn't ignore it, just that I dont know what to do about it.
    I'm really noob on Macro or scripting, hope you understand. ^^

    I just tried the one that you just made, i did a test but i only get "No data found"
    I have tried keying in groups that we are currently using.
    Any ideas why? Hope you could help me further.

    My apologies again and many thanks.

    Vincent

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Active Directory Data Using Macro

    Do you have permissions to read AD?

  13. #13
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro

    Quote Originally Posted by romperstomper View Post
    Do you have permissions to read AD?
    Yes I do. I am actually Security Admin.
    I will be using the script for this purposes. From time to time i may need to check on group membership ^^

    Thanks again.

  14. #14
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Active Directory Data Using Macro

    Hmm, try this one. (though if you are the admin, you ought to have better tools than Excel for this! )
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro

    Lol! I agree haha! But thing is, we are a small company and the company is not investing much on IT
    Anyways it's a long weekend here so I wont get to test this till Monday.
    Just the same thank you for all your help ^^
    I will be updating this post soon as I got to try the solution.

    Cheers

  16. #16
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro

    @romperstomper
    It works like a charm!
    Thank you very very much.. This is what I always wanted.
    Thanks again.


    If possible can you also help me do a search vice versa? I key in the LAN ID and then the groups that the ID is a member of will appear? It's too much to ask I know but I hope you find time hehe!
    Many thanks again! ^^

  17. #17
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Active Directory Data Using Macro

    That's a different question, so should be posed in a new thread.

  18. #18
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro

    Quote Originally Posted by romperstomper View Post
    That's a different question, so should be posed in a new thread.
    Will do. And thanks again, your work is perfect. ^^

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1