A chronological documentation test project, nothing serious, really!

11 Feb 2008 Exporting last name, first name and username from Active Directory using AdFind

Posted by

AdFind is a Windows command line Active Directory query tool. It is a mixture of ldapsearch, search.vbs, ldp, dsquery, and dsget tools with a ton of other cool features thrown in for good measure.

This post describes how I managed to export

  • Last name (surname/sn)
  • First name (givenName)
  • Username (samaccountname)

from a Active Directory and save the result to a comma separated file (CSV)

adfind.exe -b ou=ActiveDirectory,dc=example,dc=com -f "objectClass=user" sn givenName  samaccountname -nodn -adcsv > exported_users.csv

The result of this command is as follows

"Last name","First name","username"

This is a nicely formatted csv file that makes it easy to work with.

What values are available and can be searched for in a Active Directory?
If you are uncertain on the name of what you are looking for, then this line comes handy

adfind.exe -b ou=ActiveDirectory,dc=example,dc=com -s subtree |more

Remember to use the | more at the end of the line because this command lists a lot of Active Directory content.

The result of this command can contain some of the following values

cn, sb,giveNnAME,  distinguishedname, instanceType, whenCreated, whenChanged, displayName, uSNCreated, memberOf, uSNChanged, department, homeMTA, proxyAddresses, homeMBD, mDBUseDefaults, mailNickName, name, objectGUID, userAccountControl, badPwdCount, codePage, countryCode, homeDirectory, homeDrive, badPasswordTime, lastLogoff, lastLogon, logonHours, pwdLastSet, primaryGroupID, userParameters, profileParh, objectSid, accountExpires, logonCount, sAMAccountname, SamaccountType, showInAddressBook, msNPAllowDialoin, dSCorePropagationData, lastLogonTimestamp, textEncodeORAddress, mail, middleName, msExchaPoliciesExcluded, msExchHomeServerName, msExchALObjectVersion, msExchMailboxSecurityDescriptor, msExchUserAccountControl, msExchMailboxGuid

The values above are usually assosiated with a useraccount.

Tags: , , ,

Reader's Comments

  1. |

    I am trying to use Adfind to solve an issue for HR. Each month we receive a CSV file from HR that lists the emloyees who no longer work for our company. The CSV file contains simply their first and last name in two columns. What I would like to do is is run Adfind against this CSV file and output their First Last and samAccount name to a new CSV file.

    How would I do this?

    • |

      I am actually attempting solve a similar issue with HR where they have given me a smaller Access file to update the AD directory. Sadly both sets actually are not nice, filled with missing values, inconsistencies and the such.

      I figure I’m going to follow the response by
      David Archer, at
      for a similar issue.

      Should be fun

      • |


        I have actually figured this out using a powershell script. If can share this with you if you want. Please let me know.

        • |

          Hi Joe
          That would be really helpful, could you message me it please?

        • |

          Hi joe,

          I am facing the same issue as like you. can you share power shell Script to me. Thanks in advance.

          Nizamuddin Shaikh.