Active Directory Export Using Dsquery
If you're using Active Directory, we highly recommend that instead of pulling email addresses with the below method, that you integrate your Active Directory data with your KnowBe4 console. It is the easiest and most efficient way to maintain an updated user list within your console. To find out how to do this, view our Active Directory Integration manual, or check out our training video.
Otherwise, if you'd like to instead get a list of users which you can then import into your KnowBe4 console rather than automatically sync to Active Directory, you can use the below information.
The following command will return email addresses, first names, and last names for actual users (excludes public folders, distribution lists, etc.). It doesn't take disabled accounts into consideration, though:
dsquery * -filter "(&(objectClass=user)(mail=*))" -attr mail cn -limit 0 > users.txt
Microsoft also has a little note about running this in Windows Server 2008:
“To use dsquery, you must run the dsquery command from an elevated command prompt. To open an elevated command prompt, click Start, right-click Command Prompt, and then click Run as administrator.”