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 that we need to export the PowerShell command output the various type files such as – TXT, CSV, HTML and XML.
Article table of content | Click to expand
Manage E-mail addresses using PowerShell
- The structure of the PowerShell command that we use for Get information about E-mail addresses
- Viewing information about E-mail addresses on the PowerShell console
- Export information about a recipient E-mail addresses
- Using PowerShell for creating custom result fields – introduction
- Download the Managing E-mail addresses | PowerShell scripts series
Manage Email addresses | Article Series table of content | Click to expand
Manage Email addresses using PowerShell | Office 365 | Article Series
The structure of the PowerShell command that we use for Get 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):
- “Identity properties” such as DisplayName or Alias
- 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.
E-mail address properties | The “E-mail address store”
The “main store” that serve 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:
- Smtp E-mail address (primary E-mail address and Proxy E-mail address.
- x500 E-mail address.
- Non-smtp E-mail address” such as – SIP address, that is used as user identity when using the Skype for business services.
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, include information about all the
existing E-mail address, and “other address” that the recipient has such x500 E-mail address and SIP address.
Display information about Primary E-mail address
In case that 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.
Expend 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
Export information about a recipient E-mail addresses
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 former 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 be able to get information about specific property of the Exchange Online recipient, such as the recipient E-mail address, we use the PowerShell command with the “Get prefix” such as Get-Mailbox.
The PowerShell command Get-Mailbox, display the output on the PowerShell console, and in case that we need to export the information, we add 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 File name 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 a 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 a 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
It is important for us to know your opinion on this article