Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

AD users and group membership export

  • Filter
  • Time
  • Show
Clear All
new posts

  • AD users and group membership export

    Hi all

    I need to export to a text file a list of all present domain users along with the groups of which they are members.

    I already tried using the dsquery and dsget tools to give me the needed output, here's what i came to:

    DSGET user -name * -limit 0 | dsget user -samid -fn -ln -memberof > c:\textfile.txt

    The above command gives me a "dsget failed:the parameter is incorrect" error, but if i try to :

    DSGET user -name * -limit 0 | dsget user -samid -fn -ln > c:\textfile.txt

    and then

    DSGET user -name * -limit 0 | dsget user -memberof > c:\textfile2.txt

    I get both outputs correctly, the only issue at this point is that the -memberof option gives me the LDAP names of the groups to which the users belong

    Shortly, my questions are the following:

    1 - is there a way to get SAM account names, first names, last names, and memberof information, by using a single command?

    2 - how can i just get back the group names of the groups instead of getting the full LDAP names?

    Best regards, and thanks for the time spent on reading this post

    Last edited by Andrea Olei; 19th March 2012, 13:19. Reason: syntax corrected

  • #2
    Re: AD users and group membership export

    I don't know if there's a one liner you can run but you can script the whole thing.

    Here's how you can do it through PowerShell:

    $_users = Get-ADUser -Filter * -Properties *
    foreach($_user in $_users){
      $_user.givenname " " $_user.surname
      foreach($_group in $_user.memberof){
        (get-adgroup $_group.tostring())
        " "
        " "

    Network Consultant/Engineer
    Baltimore - Washington area and beyond