Skip to content

Export and display information about Email addresses using PowerShell | Office 365 | Part 6#13

In this article, we review that basic PowerShell command syntax that we use for display information about the E-mail addresses of Exchange Online recipients.

In addition, we review the PowerShell command syntax that we use in case we need to export the PowerShell command output the various type files such as – TXT, CSV, HTML, and XML.

The structure of the PowerShell command that we use for getting information about E-mail addresses

The structure of the PowerShell command that we use for display information about E-mail address is implemented as follows:

1. The specific recipient type

We use the PowerShell cmdlet prefix Get and specify the specific Exchange Online recipient type that we want to address. In the article – Introduction to the various type of Exchange Online recipients | PowerShell cmdlets | Office 365 | Part 8#13, we will be able to be impressed by the variety of the Exchange Online recipient. For now, let’s briefly say that we can specify a specific type of recipient such as “Mailbox recipient”, “Group recipient” and so on or, we can use a PowerShell cmdlets such as Get-Recipient that relate to most of the existing Exchange Online recipient’s types.

2. The recipient “standard” property that we want to display

Most of the time, we want to selective “tell” PowerShell, what is the specific object (recipient) properties that we want to view.

The definition of the properties can be “standard recipient properties” (number2):

  1. “Identity properties” such as DisplayName or Alias
  2. Recipient properties that “store” E-mail address information such as EmailAddresses or, PrimarySmtpAddress.

At the same time, PowerShell enables us to create a “custom properties” (number 3) that include the name that we define for the specific property and a “calculated output” such as – a result of a query, some calculations, and so on.

We will review this method in the Article – Adding Email addresses using PowerShell – Import from CSV file | Bulk mode | Office 365 | Part 5#13

Using the “output” of the PowerShell command – information about E-mail addresses

The “output” that we get from the PowerShell command that “get for us” information about the E-mail addresses of Exchange recipients, can be:

  • Displayed on the PowerShell console.
  • Stored in a variable.
  • Exported to various file types such as – TXT,CSV,XML and HTML.

In the following diagram, we can see the structure of the PowerShell command that we use for displaying information about “E-mail addresses” and optionally, export the information to a file.

The structure of the PowerShell command that we use for get information about E-mail addresses

E-mail address properties | The E-mail address store

The “main store” that serves as a “logical container” for all the types of E-mail addresses in Exchange Online environments is – a field named EmailAddresses.

Note – In Office 365 and Exchange Online environment there are additional “email property” fields. For example, Exchange Online uses the following properties WindowsEmailAddress and PrimarySmtpAddress for storing information about the primary E-mail address.

Exchange Online recipient – various type of E-mail addresses

Each Office 365 recipient, can have multiple E-mail address that includes:

  1. Smtp E-mail address (primary E-mail address and Proxy E-mail address.
  2. x500 E-mail address.
  3. Non-SMTP E-mail address” such as – SIP address, that is used as user identity when using the Skype for business services.
The Exchange Online container of E-mail addresses - EmailAddresses-01

Viewing information about E-mail addresses on the PowerShell console

Display E-mail address information using PowerShell console

The “default” PowerShell command syntax that we use for – display information about a recipient E-mail address is quite simple.

We need to specify:

  • The specific type of recipient such as “mailbox recipient”.
  • The identity of Exchange Online recipient (Alias or E-mail address etc.)
  • The specific properties that we want to display such as DisplayName, PrimarySmtpAddress, EmailAddresses.

PowerShell command syntax

Get-Mailbox <Identity> | Select DisplayName,EmailAddresses

PowerShell command example

Get-Mailbox Billy | Select DisplayName,EmailAddresses

In the following screenshot, we can see the result (the EmailAddresses property content). The information that stored in the EmailAddresses field includes information about all the
existing E-mail address, and “other address” that the recipient has such x500 E-mail address and SIP address.

The Exchange Online container of E-mail addresses - EmailAddresses-02

Display information about Primary E-mail address

In case we need to display information only about the Primary E-mail address of specific Exchange Online recipient, we can use the following syntax.

PowerShell command example:

Get-Mailbox Billy |Select-Object DisplayName,PrimarySmtpAddress

To display information about all Exchange Online mailboxes Primary E-mail address, we can use the following PowerShell command syntax.

PowerShell command example:

Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,PrimarySmtpAddress

The “limitation” of the PowerShell console regarding the subject of E-mail addresses

Although we can use the PowerShell console for displaying information about Exchange Online
recipient’s E-mail addresses, working with the PowerShell console, is not so comfortable because of built-in limitations.

For example, in case that a specific recipient has multiple E-mail addresses, the PowerShell console, is not able by default to display all the E-mail addresses.

Instead, the PowerShell console displays a limit number of E-mail addresses and use the three dots characters (…).

The purpose of the three dots characters (…) is to “tell” us, that there are additional E-mail addresses that cannot be displayed.

Expand the “E-mail address property”

Regarding the “issue” of displaying the “Full content” the multiple value recipient E-mail property, we can implement a “partial solution” for a specific recipient for the issue of displaying multiple E-mail addresses, but this solution is not Properly implemented in a scenario in which we need to display information about multiple recipients

In the following example, we use a PowerShell command that gets information about
Angelina E-mail addresses.

PowerShell command example

Get-Mailbox Angelina | Select-Object -ExpandProperty EmailAddresses

In the output, we can see that the “EmailAddresses” property includes many E-mail addresses.

PS C:\script> Get-Mailbox Angelina | Select-Object -ExpandProperty EmailAddresses

smtp:Angelina@o365pilot.com
smtp:kk@o365info.com
SPO:SPO_5b27dc17-68b0-442e-804b-aee5b4df9847@SPO_e95bcc9e-2927-483d-ad36-7311a7152bdd
smtp:Angelina@o365info.com
SMTP:Angelina-NEW01@o365info.com
smtp:Angelina-Alias03@o365info.com
smtp:Angelina-Alias02@o365info.com

Export information about a recipient E-mail address

One of the most common administrative tasks that relate to Exchange recipients is the need to view, and export information about the recipient E-mail address.
In many scenarios, we will need to “save” the information about the recipient E-mail address for later use by exporting the information to a file.

In the previous articles, we review the PowerShell command with the Set prefix, such as Set-Mailbox that was used to update the Exchange recipient email address.

To get information about the specific property of the Exchange Online recipient, such as the recipient’s E-mail address, we use the PowerShell command with the Get prefix, such as Get-Mailbox.

The PowerShell command Get-Mailbox displays the output on the PowerShell console. In case we need to export the information, we add an additional “part” to the PowerShell command with instructions about the file type that we want to use.

Export to file using PowerShell and supported file formats.

PowerShell supports the option of exporting command output to the following file formats: Text, CSV, HTML, and XML.

When we want to export the “command output” to a File, we need to “tell” PowerShell what is the required file format that we want to use.

In addition to the PowerShell cmdlets that we use to define the specific file format, we can “add” specific parameter that relates to the specific file format.

For example, when we wish to export PowerShell command output to a CSV (Comma Separated Value) file format, we can add additional parameters such as:

  • NoTypeInformation: This option prevents from PowerShell to add unnecessary information to the CSV file.
  • Encoding UTF8: In case that the objects such as users, or mailboxes include non-English characters, we can add this “format parameter” to enable PowerShell export information that includes non-English characters.

The Filename and the “path” parameter

A mandatory requirement when export command output to a file is the “File name.

The additional part is the “Path.” The “path” parameter defines the specific location in which we want to save the file. For example – C:\Temp.

The “path” parameter is not a mandatory parameter. Most of the times, when we export information to a file, we will also provide the “path” information.

In case that we don’t provide a specific path, PowerShell exports the file to the folder from which we run the PowerShell command.

It’s important to mention that when we provide the name of a specific path, such as C:\Temp, the PowerShell command “except” that this path is already created.

In other words, by default, the PowerShell command will not “create for us” a specific folder that was specified in the “path” parameter.

Example of PowerShell syntax for exporting information to various file types

The following section, include an example of PowerShell command syntax that we use for exporting information about the E-mail addresses of Exchange Online mailbox recipients using the four file formats.

To export command syntax is built from two parts:

  • Part 1#2 – this is the part of the Get PowerShell cmdlets, that fetch specific information.
  • Part 2#2 – this is the part in which we define the specific file format, the path, and the filename.

In the following section, we can see an example of the “export syntax” for four file formats – TXT, CSV, XML, and HTML.

Export PowerShell command output to a Text file.

Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses,EmailAddresses | Out-File C:\Temp\"Exchange Online recipients.TXT"

Export PowerShell command output to a CSV file.

Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses,EmailAddresses | Export-CSV C:\Temp\"Exchange Online recipients.CSV" –NoTypeInformation -Encoding UTF8

Export PowerShell command output to an HTML file.

Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses,EmailAddresses | ConvertTo-Html | Out-File C:\Temp\"Exchange Online recipients.HTML"

Export PowerShell command output to an XML file.

Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses,EmailAddresses | Export-Clixml C:\Temp\"Exchange Online recipients.XML"

The next article in the current article series

Display information about E-mail Addresses using PowerShell | Customizing the output using Hash Table and Custom expressions | Office 365 | Part 7#13

o365info Team

o365info Team

This article was written by our team of experienced IT architects, consultants, and engineers.

This Post Has 0 Comments

Leave a Reply

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