Need export a list of users and emailadress within a DB on exchange 2010

We run Exchange 2010 SP1 on Windows 2008 R2 server. We have 3 hub/cas and 3 db servers with exchange 2010. No other exchange servers in our system. The users in the database Im working on is linked to a user acocunts in another domain in another tree.

I need to make a list of all the users in a database with their displayname, alias, primarysmtpaddress and all their other mailaddresses.

I have tried several command without success.

Here is an example of what I have tried:

   Get-Mailbox -Database "dbname" | Select-Object alias, displayname, primarysmtpaddress

This command will list all the room mailboxes, and no users! Why will this not list the users?

I also tried what is mentioned in this article:

Still no luck. Does anyone have a good string of command that wil list my users?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


You could use the script below :
1/ save it to a file name ExchangeReporting.ps1
2/ install PowerShell 2.0 on your mailbox server
3/ install ActiveRoles Management Shell for Active Directory from PowerQuest from here :
4/ start an Exchange Management Shell and run ./ExchangeReporting.ps1

# Requires :
# - PowerShell 2.0
# - ActiveRoles Management Shell for Active Directory (

# Load ActiveRoles Management Shell for Active Directory
Add-PSSnapin Quest.ActiveRoles.ADManagement

# ***********************************
# *** Variables *********************

$strEOL = "`r`n"
$charCSVSep = ";"
$strCSVHeader = "COMPANY" + $charCSVSep + "NAME Firstname" + $charCSVSep + "Mail" + $charCSVSep + "Size (MB)"

# *** /Variables ********************
# ***********************************

# ***********************************
# *** Main **************************

$colMailboxStatistics = Get-MailboxStatistics

write-host $strCSVHeader

# Get user infos for each mailbox and store them in $colReporting
$colMailboxStatistics | ForEach-Object { 
	# Get user from AD
	$objUser = Get-QADUser -Identity $_.LegacyDN
	If ($objUser.samAccountName) {
		# Find if the mailbox is over limit
		$intMailboxSize = $_.TotalItemSize.Value.ToMB()
		If (!$objUser.Company) {
			$strCompany = "_NOT_SET_"
		} else {
			$strCompany = $objUser.Company
		# Prepare user info to store in hash $colReporting
		write-host $strCompany $charCSVSep $objUser.SN $objUser.givenName $charCSVSep $objUser.mail $charCSVSep $intMailboxSize

# *** /Main *************************
# ***********************************

Open in new window

Hope this helps !

NAF-DataAuthor Commented:
Is there really no code within Exchange Management Shell that can export a list of the users with their email address?????

I tried this script you posted, I have installed ActiveRoles Management Shell. But I get these error messages:

[PS] C:\>.\ExchangeReporting.ps1
Add-PSSnapin : Cannot add Windows PowerShell snap-in Quest.ActiveRoles.ADManagement because it is already added. Verify
 the name of the snap-in and try again.
At C:\ExchangeReporting.ps1:6 char:13
+ Add-PSSnapin <<<<  Quest.ActiveRoles.ADManagement
    + CategoryInfo          : InvalidArgument: (Quest.ActiveRoles.ADManagement:String) [Add-PSSnapin], PSArgumentExcep
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

The term 'Get-MailboxStatistics' is not recognized as the name of a cmdlet, function, script file, or operable program.
 Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\ExchangeReporting.ps1:22 char:46
+ $colMailboxStatistics = Get-MailboxStatistics <<<<
    + CategoryInfo          : ObjectNotFound: (Get-MailboxStatistics:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

COMPANY;NAME Firstname;Mail;Size (MB)
Get-QADUser : Cannot validate argument on parameter 'Identity'. The argument is null or empty. Supply an argument that
is not null or empty and then try the command again.
At C:\ExchangeReporting.ps1:29 char:34
+     $objUser = Get-QADUser -Identity <<<<  $_.LegacyDN
    + CategoryInfo          : InvalidData: (:) [Get-QADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlet
NAF-DataAuthor Commented:
I just found that I could use EMC, I added another column, called "E-Mail Addresses". Then I used the export link on the right side of the EMC. Then I imported the txt file into Excel and sorted the list based on OU, and then removed all the users I didnt need.

I find it strange that I could not do this with a simple command in the EMS. But now I got the information I wanted.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NAF-DataAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.