List mailbox attributes powershell script

List mailbox attributes PowerShell

There are certain scenarios, like a migration for example, where you are requested to list mailbox attributes to a customer. The following script will provide a comprehensive list of mailbox attributes as a .CSV file.



The script will list the most relevant attributes completely expanded without¬† the values being cut off by an ellipsis ( … ) as Exchange displays it by default :

# List Mailbox Attrbutes PS Script
# Published on
# Written by : WebBanshee

#Define OrganizationalUnit
$customer = "OrgUnitName"

#Define certain customer domain within OrganizationalUnit / !! Comment out for results on all mailboxes within the OrganizationalUnit !! 
$domain ="*DomainName*"

#CSV header , query mailbox attributes , define output
$output = "Alias;UserPrincipalName;DisplayName;PrimarySMTPAddress;FWSmptAddress;FWAddress;LegacyExchangeDN;EmailAddresses"
$org = get-mailbox -OrganizationalUnit $customer | Where-object {$_.PrimarySmtpAddress -like $domain}| Sort-Object Alias
$CustomerFile = "\Fileshare\Folder\" + $Customer + ".csv"
$output > $CustomerFile

#Loop through mailboxes and provide results
foreach ( $mailbox in $org )
$FormatEnumerationLimit = -1

$Mailbox | Select-Object Alias,UserPrincipalName,DisplayName,PrimarySmtpAddress,ForwardingSmtpAddress,ForwardingAddress,LegacyExchangeDN,EmailAddresses  

$output = $mailbox.Alias + ";" + $mailbox.UserPrincipalname + ";" + $mailbox.DisplayName + ";" + $mailbox.PrimarySmtpAddress  + ";" + $mailbox.ForwardingSmtpAddress + ";" + $mailbox.ForwardingAddress + ";" + $mailbox.LegacyExchangeDN + ";" + $mailbox.EmailAddresses

$output >> $CustomerFile

I recommend to leave the EmailAddresses attribute at the end of the query. ( As it is right now )
This is because Excel breaks the .csv formating when a result with many characters is displayed in a column somewhere in the middle.

Results will be displayed for these attributes in the following order : 

Alias; UserPrincipalName; DisplayName; PrimarySMTPAddress; ForwardingSMTPAddress; ForwardingAddress; LegacyExchangeDN; EmailAddresses

You can find a description on how to expand all details in powershell here :

Expand powershell output to display all items

I hope it comes handy when you are in need of this kind of results.

Leave a Reply

Your email address will not be published. Required fields are marked *