For certain jobs it is often useful to have a current list of all email addresses on hand. Maintaining this list is of course very complex and also impractical. For this reason, we would like to show you below how easily you can create a current list of all users including the primary email address .
The easiest and fastest way to create this email address list is with the PowerShell console. To do this, simply start a PowerShell console with administrative rights and then execute the following command.
import module activedirectory
This will load special PowerShell modules so that commands for querying the Active Directory are also available. Then you should then execute the following PowerShell command.
get-aduser filter * -SearchBase “dc = ????, dc = ??” -Properties display name, email address | select displayname, emailaddress
We have shown you the result here once.
The ” ???? “In the PowerShell command, of course, you have to replace it with your domain name. However, this list of email addresses is completely unsorted and is not listed alphabetically. If you want to sort the list by the ” display name ” of the user, the command is as follows.
get-aduser filter * -SearchBase “dc = ????, dc = ??” -Properties display name, email address | sort displayname | select displayname, emailaddress
Of course, it is also possible to sort the list by email address.
Of course, the output of the e-mail address list on the screen is not particularly useful. By subsequently adding the command, you can then export the email addresses including the user names in a text file.
get-aduser filter * -SearchBase “dc = ????, dc = ??” -Properties display name, email address | sort displayname | select displayname, emailaddress> C: PATH FILENAME.TXT
Now you can edit this text file with all email addresses and the corresponding username easily and conveniently in Excel.
In many other articles we went into the possibilities of the “get-aduser” PowerShell command .
– Find a user’s LastLogon (last login) in the AD using Get-ADUser
– List all deactivated AD accounts
using PowerShell
– Query members of an AD group using PowerShell – Query all user accounts information of a local user
– Count the number of AD (Active Directory) objects using PowerShell
– List AD user accounts that have entered a profile path
– Find out which AD user has never logged in