How to export user aliases from Microsoft Entra using PowerShell

 
 
  • Gérald Barré

Microsoft Graph is a REST API that allows you to interact with Microsoft 365 services. You can use it to automate tasks such as creating users, updating their properties, or exporting data. In this post, I'll show you how to export user email addresses and aliases from Microsoft Entra using PowerShell.

First, you need to install the Microsoft.Graph module:

PowerShell
Install-Module Microsoft.Graph -Scope CurrentUser

Then, you need to connect to the Microsoft Graph API. You can use the Connect-MgGraph cmdlet to authenticate. You need to specify the scopes you want to use. In this case, we need to read all users. Note that you can use Find-MgGraphCommand to find the required permissions.

PowerShell
Connect-MgGraph -Scopes "User.Read.All" -NoWelcome
$User = Get-MgUser -UserId "sample@meziantou.net" -Property "ProxyAddresses"

# Remove the smtp: prefix and sort the aliases
$User.ProxyAddresses | ForEach-Object { $_ -replace '^smtp:', '' } | Sort-Object

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub