{"id":2936,"date":"2019-01-03T11:00:27","date_gmt":"2019-01-03T09:00:27","guid":{"rendered":"https:\/\/msb365.abstergo.ch\/?p=2936"},"modified":"2023-06-23T13:07:52","modified_gmt":"2023-06-23T11:07:52","slug":"add-remove-and-manage-email-alias-using-powershell","status":"publish","type":"post","link":"https:\/\/www.msb365.blog\/?p=2936","title":{"rendered":"Add, remove and manage email alias using Powershell"},"content":{"rendered":"<p>This short article is about a returning question about how to add or remove smtp alias addresses using the Exchange management shell.<\/p>\n<p>\u00a0<\/p>\n<p>Before we start, we need to check how the mailbox is configured and which the mail address aliases we have already set are.<\/p>\n<p>To do that we can run the following PowerShell command:<\/p>\n<pre class=\"\">Get-Mailbox MAILBOX | select \u2013expand emailaddresses alias<\/pre>\n<p>\u00a0<\/p>\n<p>By running this command, we get an export, which could look like the following example:<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-2937\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/12\/1.png\" alt=\"\" width=\"837\" height=\"697\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/12\/1.png 837w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/12\/1-300x250.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/12\/1-768x640.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/12\/1-600x500.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/12\/1-780x650.png 780w\" sizes=\"(max-width: 837px) 100vw, 837px\" \/><\/p>\n<p>However, if we want now to add an additional alias to our specific mailbox, we can use the following command:<\/p>\n<pre class=\"\">Set-Mailbox MAILBOX \u2013EmailAddresses @{Add=\u2019alias@contoso.com\u2019}<\/pre>\n<p>\u00a0<\/p>\n<p>It is very important to do that in this way, if we try to add an email address without the @{ part of the command, all other entries will be removed.<\/p>\n<p>\u00a0<\/p>\n<p>However, to remove a single alias of a Mailbox, the command looks quite similar. We can run the following command:<\/p>\n<pre class=\"\">Set-Mailbox MAILBOX \u2013EmailAddresses @{remove=\u2019alias@contoso.com\u2019}<\/pre>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p><strong>Searching email addresses with PowerShell<\/strong><\/p>\n<p>With PowerShell, we can do more than just add or remove single email address aliases.<\/p>\n<p>Another very helpful feature is to search for an email address. In the following example we are searching for an email address which starts \u2018da\u2019. To get a usable export, we also use the (*) after \u2018da\u2019 which is called wildcard for the result. That means, we will get a list with all mail addresses starting with the letters \u2018da\u2019.<\/p>\n<p>The command for that looks like this:<\/p>\n<pre class=\"\">Get-Recipient \u2013Filter {EmailAddress \u2013like \u2018smtp:da*\u2019 \u2013or EmailAddress \u2013like \u2018da*\u2019}<\/pre>\n<p>\u00a0<\/p>\n<p>The command above will return the user of the object that has the searched name or letters in the email address, but it won\u2019t show where. So select the EmailAddress field and expand it to show all values of the multi value object.<\/p>\n<p>\u00a0<\/p>\n<pre class=\"\">Get-Recipient -Filter {EmailAddresses -like 'smtp:da*'} -Properties Name,Emailaddresses | select Name,Emailaddresses -ExpandProperty Emailaddresses<\/pre>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>Photo by\u00a0<a href=\"https:\/\/unsplash.com\/photos\/_l8ZdgJ9m7w?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText\">Biel Morro<\/a>\u00a0on\u00a0<a href=\"https:\/\/unsplash.com\/search\/photos\/easy-shell?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText\">Unsplash<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This short article is about a returning question about how to add or remove smtp alias addresses using the Exchange management shell. \u00a0 Before we start, we need to check how the mailbox is configured and which the mail address aliases we have already set are. To do that we can run the following PowerShell [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2938,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1923,2,3],"tags":[],"class_list":["post-2936","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microsoft-365","category-exchange","category-powershell"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/2936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2936"}],"version-history":[{"count":3,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/2936\/revisions"}],"predecessor-version":[{"id":5194,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/2936\/revisions\/5194"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/media\/2938"}],"wp:attachment":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}