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

Posted on 2012-03-22
Last Modified: 2012-08-14
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?
Question by:NAF-Data
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 37753203

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 !


Author Comment

ID: 37756175
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

Accepted Solution

NAF-Data earned 0 total points
ID: 37756248
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.

Author Closing Comment

ID: 37775634

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Move a Database to a different server 4 58
Certificate Questions - Exchange 2016 11 44
office 365 5 34
Powershell - getting input from CSV File 8 15
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question