{"id":8548,"date":"2023-12-31T00:08:57","date_gmt":"2023-12-31T00:08:57","guid":{"rendered":"https:\/\/cheapwindowsvps.com\/blog\/how-to-retrieve-all-smtp-email-addresses-using-powershell-in-exchange\/"},"modified":"2025-01-20T10:17:50","modified_gmt":"2025-01-20T10:17:50","slug":"how-to-retrieve-all-smtp-email-addresses-using-powershell-in-exchange","status":"publish","type":"post","link":"https:\/\/cheapwindowsvps.com\/blog\/how-to-retrieve-all-smtp-email-addresses-using-powershell-in-exchange\/","title":{"rendered":"How to Retrieve All SMTP (Email) Addresses Using PowerShell in Exchange"},"content":{"rendered":"<p><p>Occasionally, it may be necessary to export a complete list of email addresses in your Exchange organization. This article will guide you on how to obtain and export all assigned SMTP addresses to a CSV file in Exchange Server or Microsoft 365 (Exchange Online) using PowerShell.<\/p>\n<\/p>\n<p><p>Here&#8217;s how to connect to your Exchange organization:<\/p>\n<\/p>\n<ul>\n<li>The Exchange Management Shell (EMS) module allows you to manage on-premises Exchange Server, or alternatively, you can <a href=\"https:\/\/woshub.com\/connect-exchange-microsoft-365-remote-powershell\/\" rel=\"nofollow noopener\" target=\"_blank\">connect to Exchange remotely from a regular PowerShell console<\/a>.<\/li>\n<li>To connect Microsoft 365 tenant, utilize the <a href=\"https:\/\/woshub.com\/powershell-connect-and-manage-exchange-online\/\" rel=\"nofollow noopener\" target=\"_blank\">Exchange Online PowerShell module<\/a>.<\/p>\n<p><p>You have the option to use <a href=\"https:\/\/woshub.com\/powershell-certificate-based-auth-exchange-azure\/\" rel=\"nofollow noopener\" target=\"_blank\">certificate-based authentication to sign in to Exchange Online<\/a> from within PowerShell.<\/p>\n<\/li>\n<\/ul>\n<p><p>To view all primary and additional SMTP addresses for a specific Exchange mailbox, run this command:<\/p>\n<p><code>Get-Mailbox testmax |Select-Object DisplayName,PrimarySmtpAddress,EmailAddresses|fl<\/code><\/p>\n<ul>\n<li>The <code>SMTP<\/code> address in <em>uppercase<\/em> contains the primary email address.<\/li>\n<li>The <em>lowercase<\/em> <code>smtp<\/code> values are the secondary (alias) email addresses.<\/li>\n<\/ul>\n<p>The <em>proxyAddresses<\/em> attribute is used to set the email delivery address in the on-premises Active Directory.<\/p>\n<\/p>\n<p><p>A user is assigned multiple additional SMTP addresses, which are preserved in the EmailAddresses string attribute. Other forms of addresses might also exist within this attribute; hence, to obtain a compilation of all the SMTP addresses of a mailbox, execute the command below:<\/p>\n<\/p>\n<p><p><code>Get-Mailbox testmax | Select-Object DisplayName,PrimarySmtpAddress, @{Name=\"SMTPAliases\";Expression={($_.EmailAddresses | Where-Object { $_ -match \"^smtp:\" } | ForEach-Object {$_ -replace \"smtp:\",\"\"}) -join \",\" }}<\/code><\/p>\n<\/p>\n<p><p>The following command showcases all primary addresses and aliases for every user mailbox and <a href=\"https:\/\/woshub.com\/convert-user-shared-mailbox-exchange\/\" rel=\"nofollow noopener\" target=\"_blank\">shared mailboxes in Exchange<\/a> and <a href=\"https:\/\/woshub.com\/export-csv-file-powershell\/\" rel=\"nofollow noopener\" target=\"_blank\">exports the results to a CSV file<\/a>:<\/p>\n<\/p>\n<p><p><code>Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress, @{Name=\"SMTPAliases\";Expression={($_.EmailAddresses | Where-Object { $_ -match \"^smtp:\" } | ForEach-Object {$_ -replace \"smtp:\",\"\"}) -join \",\" }}&nbsp;| Export-Csv \"C:PSList-All-SMTP-Addresses.csv\" -NoTypeInformation -Encoding UTF8<\/code><\/p>\n<\/p>\n<p><p>The Get-Mailbox cmdlet displays only information about users and shared mailboxes.<\/p>\n<\/p>\n<p><p>In Active Directory (or Azure AD), there may be other types of objects with SMTP addresses assigned (mail-enabled objects): <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/winitpro.ru\/index.php\/2020\/08\/14\/gruppy-rassylok-v-exchange-server\/\">distribution groups<\/a>, contacts, and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/woshub.com\/manage-azure-ad-microsoft-365-groups\/\">Microsoft 365 groups<\/a> (Unified Groups in Azure). Use the Get-Recipient cmdlet to list the SMTP addresses of all the objects in an Exchange organization\/tenant:<\/p>\n<\/p>\n<p><p><code>Get-Recipient -ResultSize Unlimited | Select-Object DisplayName, RecipientType, PrimarySmtpAddress, @{Name=\"SMTPAliases\";Expression={($_.EmailAddresses | Where-Object { $_ -match \"^smtp:\" } | ForEach-Object {$_ -replace \"smtp:\",\"\"}) -join \",\" }}<\/code><\/p>\n<\/p>\n<div>\n<p>In this case, we have a list of the SMTP addresses of all types of Exchange objects. To export only SMTP addresses of a specific object type, add the following parameter to the first cmdlet<\/p>\n<p><code>Get-Recipient -ResultSize Unlimited -RecipientType your_object_type | \u2026<\/code><\/p>\n<p>Possible types of Exchange objects:<\/p>\n<\/p><\/div>\n<\/p>\n<ul>\n<li>DynamicDistributionGroup<\/li>\n<li>MailContact<\/li>\n<li>MailNonUniversalGroup<\/li>\n<li>MailUniversalDistributionGroup<\/li>\n<li>MailUniversalSecurityGroup<\/li>\n<li>MailUser<\/li>\n<li>PublicFolder<\/li>\n<li>UserMailbox<\/li>\n<\/ul>\n<div>\n<p>If you need to find <a href=\"https:\/\/woshub.com\/find-duplicate-smtp-exchange\/\" rel=\"nofollow noopener\" target=\"_blank\">Exchange objects with the same (duplicate) recipient SMTP address<\/a>, run:<\/p>\n<p><p><code>Get-Recipient -resultsize unlimited | where {$_.EmailAddresses -like \"*[email&nbsp;protected]*\"}<\/code><\/p>\n<\/div>\n<\/p>\n<p><p>You can also get a flat list of SMTP addresses in Exchange:<\/p>\n<\/p>\n<p><p><code>Get-Recipient | Select-Object -ExpandProperty EmailAddresses | Where-Object { $_ -match \"^smtp:\" } | ForEach-Object { $_.Replace(\"smtp:\", \"\").Replace(\"SMTP:\", \"\") }<\/code><\/p>\n<\/p>\n<div>\n<p><p>Unique <a href=\"https:\/\/woshub.com\/send-email-teams-channel\/\" rel=\"nofollow noopener\" target=\"_blank\">SMTP addresses were also generated for the Microsoft Teams channel<\/a>.<\/p>\n<\/p>\n<p><p>View the number of unique SMTP addresses in your Exchange organization:<\/p>\n<\/p>\n<p><p><code>Get-Recipient -ResultSize Unlimited | Select-Object -ExpandProperty EmailAddresses | Where-Object { $_ -match \"^smtp:\" }| measure-object<\/code><\/p>\n<\/p>\n<\/div>\n<div>\n<p><!-- Contents of the scripts, scripts themselves, styles, id, class and other mentioned attributes removed --><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Occasionally, it may be necessary to export a complete list of email addresses in your Exchange organization. This article will guide you on how to obtain and export all assigned SMTP addresses to a CSV file in Exchange Server or Microsoft 365 (Exchange Online) using PowerShell. Here&#8217;s how to connect to your Exchange organization: The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8549,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127,128,117],"tags":[],"class_list":["post-8548","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-exchange","category-microsoft-365","category-powershell"],"_links":{"self":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/comments?post=8548"}],"version-history":[{"count":2,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8548\/revisions"}],"predecessor-version":[{"id":10362,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8548\/revisions\/10362"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media\/8549"}],"wp:attachment":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media?parent=8548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/categories?post=8548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/tags?post=8548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}