{"id":1558,"date":"2018-03-29T17:48:01","date_gmt":"2018-03-29T15:48:01","guid":{"rendered":"https:\/\/msb365.abstergo.ch\/?p=1558"},"modified":"2023-06-23T13:25:56","modified_gmt":"2023-06-23T11:25:56","slug":"adding-a-domain-to-office-365-by-powershell","status":"publish","type":"post","link":"https:\/\/www.msb365.blog\/?p=1558","title":{"rendered":"Adding a Domain to Office 365 with PowerShell"},"content":{"rendered":"<p>One of my customers has bought another company, so they needed to add the new company domain to their environment. This company has a hybrid exchange organization and I had to do some simple steps.<\/p>\n<p>As a first step I recommend you to start the PowerShell documentation as I have described in one of my previous article \u201c<strong><a href=\"https:\/\/msb365.abstergo.ch\/?p=1202\" target=\"_blank\" rel=\"noopener\">10 Useful PowerShell cmdlets for Exchange<\/a><\/strong>\u201d<\/p>\n<pre>Start-Transcript<\/pre>\n<p>Now we have documentation about all steps we have done for these tasks.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-1566\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/1-6.png\" alt=\"\" width=\"933\" height=\"274\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/1-6.png 933w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/1-6-300x88.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/1-6-768x226.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/1-6-600x176.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/1-6-780x229.png 780w\" sizes=\"(max-width: 933px) 100vw, 933px\" \/><\/p>\n<p>Now we need to connect to the right tenant, where we want to add our new domain. To do that, we need this command:<\/p>\n<pre>Connect-MsolService<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1564\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/2-5.png\" alt=\"\" width=\"687\" height=\"481\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/2-5.png 687w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/2-5-300x210.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/2-5-600x420.png 600w\" sizes=\"(max-width: 687px) 100vw, 687px\" \/><\/p>\n<p>After entering our credentials, we will be redirected to our tenant. Now we can check the status of our existing domains, which are assigned to our tenant, for that we run:<\/p>\n<pre>Get-MsolDomain<\/pre>\n<p>Here we see now the Names, Status and Authentication settings of our existing domain.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1567\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/3-6.png\" alt=\"\" width=\"567\" height=\"291\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/3-6.png 567w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/3-6-300x154.png 300w\" sizes=\"(max-width: 567px) 100vw, 567px\" \/><\/p>\n<p>To add another domain to this tenant, we can run the following command:<\/p>\n<pre>New-MsolDomain \u2013Name \u201ccontoso.com\u201d<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1648\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/4-6.png\" alt=\"\" width=\"336\" height=\"135\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/4-6.png 336w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/4-6-300x121.png 300w\" sizes=\"(max-width: 336px) 100vw, 336px\" \/><\/p>\n<p>Simple, right? However, we are not finished yet. A new domain always needs to be verified, and to do that we will use the public DNS. That means we need a TXT-Record which we need to create in the public DNS zone of the domain, we want to add to our tenant. That we are able to do that and that we know what we have entry we have to create in the public DNS, we run this command:<\/p>\n<pre>Get- MsolDomainVerificationDns \u2013DomainName contoso.com \u2013Mode DnsTxTRecord<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1649\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/5-3.png\" alt=\"\" width=\"518\" height=\"99\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/5-3.png 518w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/5-3-300x57.png 300w\" sizes=\"(max-width: 518px) 100vw, 518px\" \/><\/p>\n<p>With this information we switch to our public DNS and create the TXT-record.<\/p>\n<p>After we have created the record, we need to wait a bit. DNS needs a bit of time till the replication is done. To improve the changes that Microsoft gets the new record, we go back to our PowerShell console and hit the following command to verify, if the new DNS entry is already ready:<\/p>\n<pre>nslookup -type=TXT contoso.com 8.8.8.8<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1651\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/7-1.png\" alt=\"\" width=\"623\" height=\"310\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/7-1.png 623w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/7-1-300x149.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/7-1-600x299.png 600w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/p>\n<p>If the result looks good for us, and we get the positive reply, we need to do one final step on the tenant shell. We need to confirm the new Domain. This we do with the following command:<\/p>\n<pre>Confirm-MsolDomain -DomainName contoso.com<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1652\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/8-1.png\" alt=\"\" width=\"684\" height=\"77\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/8-1.png 684w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/8-1-300x34.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/8-1-600x68.png 600w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/><\/p>\n<p>As we can see in the output of this command, everything went well.<\/p>\n<p>To be sure how it looks now, we can run again one of our first commands to see if the new domain looks how it should do:<\/p>\n<pre>Get-MsolDomain<\/pre>\n<p>And if we like what we see, we just have to stop our documentation with:<\/p>\n<pre>Stop-Transcript<\/pre>\n<p>Now we are done.<\/p>\n<p>&nbsp;<\/p>\n<p>The next task I want to show you here is what I had to do on the Exchange site.<\/p>\n<p>We have now registered the new domain to our tenant, now we also need to present the new domain to the Exchange environment. To do that I have written a mini script which I was running on the Exchange management shell on the on-premises Exchange:<\/p>\n<pre>#region Create accepted domains on the on-premise server\r\nWrite-Host 'Creating the accepted domains for Contoso and Fabrikam' -ForegroundColor cyan\r\nNew-AcceptedDomain -Name 'contoso.com' -DomainName contoso.com -DomainType Authoritative\r\nNew-AcceptedDomain -Name ' fabrikam.net ' -DomainName fabrikam.net -DomainType Authoritative\r\n#set brake for replication\r\nsleep -seconds 12\r\nWrite-Host 'Accepted Domains sucessfully created!' -ForegroundColor green\r\n#endregion<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1653\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/9-1.png\" alt=\"\" width=\"953\" height=\"210\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/9-1.png 953w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/9-1-300x66.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/9-1-768x169.png 768w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/9-1-600x132.png 600w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/9-1-780x172.png 780w\" sizes=\"(max-width: 953px) 100vw, 953px\" \/><\/p>\n<p>That the users, which were working in the bought company are still available on their old mail addresses, we need to add the old address to their new mailboxes, they have got in the new company. I will not post now the whole script I was running for that. However, I will post one example how doing that by PowerShell:<\/p>\n<pre>Set-RemoteMailbox -Identity \"Desmond.Miles\" -EmailAddresses @{add=\"D.Miles@contoso.com\"}<\/pre>\n<p>Now we have one last thing to do. We need to modify the MX-Records of the Domain Contoso.com. When we have changed them, the mail flow will go to the right destination.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1654\" src=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/10-1.png\" alt=\"\" width=\"685\" height=\"213\" srcset=\"https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/10-1.png 685w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/10-1-300x93.png 300w, https:\/\/msb365.abstergo.ch\/wp-content\/uploads\/2018\/03\/10-1-600x187.png 600w\" sizes=\"(max-width: 685px) 100vw, 685px\" \/><\/p>\n<p>This is all for the moment, I hope this article was a little help for you\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of my customers has bought another company, so they needed to add the new company domain to their environment. This company has a hybrid exchange organization and I had to do some simple steps. As a first step I recommend you to start the PowerShell documentation as I have described in one of my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3094,"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":[12,1923,2,3],"tags":[],"class_list":["post-1558","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","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\/1558","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=1558"}],"version-history":[{"count":11,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/1558\/revisions"}],"predecessor-version":[{"id":5244,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/posts\/1558\/revisions\/5244"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=\/wp\/v2\/media\/3094"}],"wp:attachment":[{"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.msb365.blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}