Export Microsoft 365 Licensed User Email Addresses to CSV with PowerShell
Question details
Export email addresses for licensed user mailboxes to a CSV file while excluding distribution groups and shared mailboxes.

- Product
- Microsoft 365 and Exchange Online
- Device & OS
- not provided
- Scenario
- An administrator needs a list of licensed user recipients for reporting or review.
- Observed behavior
- The desired CSV contains licensed user mailbox addresses without shared mailboxes or distribution groups.
Use an account authorized to read Microsoft 365 users and Exchange Online mailboxes. You may need administrator consent for the Microsoft Graph User.Read.All permission and permission to install PowerShell modules.
Export licensed user mailboxes with Microsoft Graph and Exchange Online PowerShell
Use this method to check license assignments and export primary email addresses for user mailboxes only.
Microsoft Graph identifies users with assigned licenses, while Exchange Online identifies user mailboxes. This excludes shared mailboxes and distribution groups, but it does not verify that a particular Exchange license is assigned.
The older Get-MsolUser approach uses the retired MSOnline module. Microsoft Graph PowerShell is the current alternative.
Open PowerShell and run: Install-Module Microsoft.Graph.Users -Scope CurrentUser; Install-Module ExchangeOnlineManagement -Scope CurrentUser. If the modules are already installed, you can skip this step.
Run Connect-MgGraph -Scopes "User.Read.All", then run Connect-ExchangeOnline and sign in when prompted. Grant or request administrator consent if required.
Run the following commands, changing the output path if needed: $licensed = @{} Get-MgUser -All -Property Id,DisplayName,UserPrincipalName,AssignedLicenses | Where-Object { $_.AssignedLicenses.Count -gt 0 } | ForEach-Object { $licensed[$_.Id] = $_ } $results = Get-EXOMailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited -Properties ExternalDirectoryObjectId,PrimarySmtpAddress | ForEach-Object { $user = $licensed[$_.ExternalDirectoryObjectId.ToString()] if ($user) { [PSCustomObject]@{ DisplayName = $user.DisplayName UserPrincipalName = $user.UserPrincipalName EmailAddress = $_.PrimarySmtpAddress.ToString() } } } $results | Export-Csv -Path ".\LicensedUsers.csv" -NoTypeInformation -Encoding UTF8
Open LicensedUsers.csv from the current PowerShell directory and check the EmailAddress column. If no users match, check the account permissions, license assignments, and mailbox types before running the export again.

Review Your Licensed User CSV in WPS Spreadsheet
After exporting from Microsoft 365, open the CSV in WPS Spreadsheet to review and organize the results. WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility for an easy transition.

Frequently Asked Questions
Why use Microsoft Graph instead of Get-MsolUser?
Get-MsolUser belongs to the retired MSOnline PowerShell module. Use Get-MgUser from Microsoft Graph PowerShell to retrieve user license assignments.
Does the export include shared mailboxes or distribution groups?
No. The Get-EXOMailbox command uses -RecipientTypeDetails UserMailbox, so shared mailboxes and distribution groups are excluded.
Is the user principal name always the email address?
No. A user principal name is a sign-in identifier and can differ from the primary SMTP address. The export includes both UserPrincipalName and EmailAddress.
Where is the exported CSV saved?
The path .\LicensedUsers.csv saves the file in the current PowerShell directory. Run Get-Location to see that directory, or replace the path in Export-Csv with another writable location.
Does an assigned license guarantee that Exchange is enabled for the user?
No. The script checks for at least one assigned license and an Exchange Online user mailbox; it does not check whether a specific Exchange service plan is enabled.




