Chat with us, powered by LiveChat

Blog

Back

New Script: Office 365 aliases inventory

17 Aug 2017 by Vasil Michev

An inventory of Office 365 aliases is one of the most commonly requested Office 365/Exchange Online reports. The script in this post generates a list of all addresses (aliases) in the company. A quick search will return plenty of similar scripts for this report, but the one we’ve demonstrated here is a fully up to date version that handles the latest recipient types available in Office 365, as well as support some new alias types.
The core of the script is the Get-Recipient cmdlet, which can be used to return all recipient types we are interested in and (some of) their properties. By default, the script will return only ‘regular’ User mailboxes, and as usual, we’ve introduced switch parameters to handle the inclusion of different recipient types, for example the –IncludeSharedMailboxes switch for Shared mailboxes. Since the number of recipient types covered is 15, not all of them get their own switches. The –IncludeDGs switch will cover all Dynamic Distribution Groups, “regular” Distribution Groups, mail-enabled Security Groups and Room Lists. Similarly, the –IncludeMailUsers switch will cover Mail Users and the recently introduced Guest Mail User objects. Check out lines 33-48 in the script for all the recipient related parameters and their descriptions. You can also use the –IncludeAll switch to cover all supported recipients.
For completeness, X500 aliases are also included. If you want to include other types of aliases, such as the SIP addresses used by Skype for Business or the SPO addresses used by SharePoint Online and the Office Graph, you can specify the corresponding –IncludeSIPAliases and –IncludeSPOAliases switches. In all fairness, you should not care at all about the SPO aliases as they are managed automatically by the service, although we’ve seen some reports about issues with duplicate entries causing trouble. Another way to include this information in the report is to specify the –IncludeAll switch. Finally, information about the ExternalEmailAddress attribute is also included for any Mail User or Mail Contact objects.
In order to speed up the script execution and help minimize issues when running it against large environments, we wrap the execution of the Get-Recipient cmdlet via Invoke-Command and only get a minimal set of parameters for each recipient found. For the same reason, we use a workaround in order to include the UserPrincipalName value, as the Get-Recipient cmdlet does not expose this parameter. Instead, we use the WindowsLiveID attribute, which should match the UPN for any relevant object type. This saves us from having to run additional cmdlets in order to get the UPN value, and therefore greatly reduces the script execution time. That said, it still might take a substantial amount of time to run the script, something like a minute per each 1000 recipients. Because a single cmdlet is being executed against Exchange Online, no progress bar is provided this time, so don’t get panicked if nothing seems to happen for a long time!
Before we get to the script itself, here are some points about the output. By default, the script will write to a CSV file, and also store the output to the global $varAliases variable. You can specify a different location or name for the CSV file, or designate a different variable by editing the last line of the script. If you do not like the default output (one line per each alias), you can use the –CondensedOutput switch to get the “condensed” output, which reduces the CSV file to one line per each recipient instead. An example of the default output is shown below:

The above was generated by running the script with the –IncludeAll switch:
.\O365_aliases_inventory.ps1 -IncludeAll
Additional examples of the script usage can be found in the built-in help. It’s worth mentioning that the script does not include any code to handle Exchange Online connectivity, you will have to take care of this part yourself. If no valid Exchange Online session is detected, then the script will fail.
The script file can be downloaded from the TechNet Gallery here: https://gallery.technet.microsoft.com/Office-365-aliases-b3937767
Should you want to add additional attributes to the script/report, make sure to add them to the list in line 77. As always, don’t hesitate to send us questions or feedback in the comments section of the blog!
Cogmotive is the leading global provider of enterprise level reporting and analytics applications for Office 365. Find out more now.

Vasil Michev has closely followed the evolution of Microsoft's Productivity Cloud offerings since the very beginnings with BPOS. With a career that has spanned the industry, from Frontline Engineer to Consultant, Michev has a unique, and wide-reaching experience, encompassing all stages of the Office 365 adoption lifecycle. In his spare time, he enjoys getting involved in various Office 365 communities, helping like-minded people, and writing blog posts. His contributions have earned him the Microsoft MVP Award three times.