Microsoft Graph is a REST API for interacting with Microsoft 365 services. You can use it to automate tasks such as creating users, updating their properties, or exporting data. This post shows how to export user email addresses and aliases from Microsoft Entra using PowerShell.
First, install the Microsoft.Graph module:
PowerShell
Install-Module Microsoft.Graph -Scope CurrentUser
Next, connect to the Microsoft Graph API using the Connect-MgGraph cmdlet. You must specify the required permission scopes; in this case, read access to 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!