<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Imad Benbouzid’s Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/imadbenbouzid/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/imadbenbouzid/feed.xml</link>
    <description>Cloud Solution Architect at Microsoft</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:41:34 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Office 365 Custom Domain Automation</title>
      <link>https://docs.microsoft.com/archive/blogs/imadbenbouzid/office-365-custom-domain-automation</link>
      <pubDate>Fri, 31 Mar 2017 23:50:32 GMT</pubDate>
      <dc:creator><![CDATA[ImadBenbouzid]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/imadbenbouzid/?p=25</guid>
      <description><![CDATA[Office 365 lets you add your GoDaddy domain in a three-step process that takes minutes. Using the...]]></description>
      <content:encoded><![CDATA[<span>Office 365 lets you add your GoDaddy domain in a three-step process that takes minutes. Using the domains setup wizard in Office 365, you'll provide the domain name you want to add to Office 365, and then the automatic process at GoDaddy makes setup fast and simple.</span>

You can see how it works <a href="https://support.office.com/en-gb/article/You-can-quickly-add-a-GoDaddy-domain-to-Office-365-ec6f4bd8-5996-4505-ba68-afaf8a141fb9">here</a>

What about if you own a domain from another domain registrar ? What about if you want to automate this custom domain verification through a script?

Below is a solution leveraging Azure DNS.

&nbsp;
<h4><span>Install required software</span></h4>
As a prerequisite you need to install required software :
<ul>
 	<li>Microsoft Online Services Sign-in Assistant</li>
 	<li>Windows Azure Active Directory Module for Windows PowerShell</li>
 	<li>Azure Resource Manager DNS module</li>
</ul>
These PowerShell lines will do the work for you:<code>
#Download and install MSOL
<span style="color: #0000ff">Invoke-WebRequest -Uri https://download.microsoft.com/download/5/0/1/5017D39B-8E29-48C8-91A8-8D0E4968E6D4/en/msoidcli_64.msi -OutFile c:\msoidcli_64.msi</span>
<span style="color: #0000ff">Start-Process -FilePath msiexec -ArgumentList /i, c:\msoidcli_64.msi, /quiet -Wait</span>
#Download and install Windows Azure Active Directory Module for Windows PowerShell
<span style="color: #0000ff">Invoke-WebRequest -Uri https://go.microsoft.com/fwlink/p/?linkid=236297 -OutFile c:\AdministrationConfig-en.msi</span>
<span style="color: #0000ff"> Start-Process -FilePath msiexec -ArgumentList /i, c:\AdministrationConfig-en.msi, /quiet -Wait</span>
<span>#Install Azure RM DNS</span>
</code><code><span style="color: #0000ff">Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force</span>
<span style="color: #0000ff"> Install-Module AzureRM.Dns -Confirm:$false -Force</span>
</code>

&nbsp;
<h4>Connect to your tenant</h4>
Then you will have to connect to Office 365 and Azure which will host your DNS zone. Setting some parameters will be helpful for next steps:

<code><span>#Parameters</span>
<span style="color: #0000ff">$DomainName = "yourdomain"</span>
<span style="color: #0000ff"> $Username= "admin@xxxxxxx.onmicrosoft.com"</span>
<span style="color: #0000ff"> $Password = "O365Pass"</span>
<span style="color: #0000ff"> $AzureUsername = "admin@XXXXXX.com"</span>
<span style="color: #0000ff"> $AzurePassword = "AzurePass"</span>
<span style="color: #0000ff"> $ResourceGroupName = "MyRG"</span>
<span style="color: #0000ff"> $subscriptionName = "MySubName"</span></code>

<code><span style="color: #0000ff">write</span> "##################Connect to Office 365#########################"
<span style="color: #0000ff">$SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force</span>
<span style="color: #0000ff"> [PSCredential ]$cred = New-Object PSCredential ($Username, $SecurePassword)</span>
#Login to O365
<span style="color: #0000ff">Import-Module MSOnline</span>
<span style="color: #0000ff"> Connect-MsolService -Credential $cred</span></code>

<code><span style="color: #0000ff">write</span> "##################Connect to Azure##############################"
<span style="color: #0000ff">$SecurePassword = ConvertTo-SecureString -String $AzurePassword -AsPlainText -Force</span>
<span style="color: #0000ff"> [PSCredential ]$cred = New-Object PSCredential ($AzureUsername, $SecurePassword)</span>
#login to Azure
<span style="color: #0000ff">Login-AzureRmAccount -Credential $cred</span>
<span style="color: #0000ff"> Select-AzureRmSubscription -SubscriptionName $subscriptionName</span></code>

&nbsp;
<h4>DNS Domain Delegation</h4>
Next step is to create an Azure DNS Zone and update your domain name servers (domain delegation)
<code>#Create new Zone
<span style="color: #0000ff">New-AzureRmDnsZone -Name $DomainName -ResourceGroupName $ResourceGroupName -ErrorAction Continue</span></code>

Azure DNS is not a name registrar service (Azure DNS does not support purchasing of domain names) but a service providing name resolution using Microsoft Azure infrastructure and enabling automation.

Therefore, after creating the Azure DNS Zone you should delegate your domain in your registrar provider to use Azure DNS Name servers located in your zone. For more details arround zone delegation refer to this <a href="https://docs.microsoft.com/en-us/azure/dns/dns-domain-delegation">article</a>.

&nbsp;
<h4>Custom Domain Verification and  Setup</h4>
Once the domain delegation is setup Office 365 custom domain creation and verification is straight forward. Following PowerShell lines will add the custom domain in Office 365, populate Azure DNS zone with the TXT record needed for verification, run the verification, then create Exchange Online DNS entries.

<code>write "###############Add DomainName in Office 365#########################"
<span style="color: #0000ff">New-MsolDomain -Name $DomainName -ErrorAction Continue</span>
<span style="color: #0000ff"> Get-MsolDomain</span></code>

<code>write "###############Get DNS verification code############################"
<span style="color: #0000ff">$txt=Get-MsolDomainVerificationDns -DomainName $DomainName -Mode DnsTxtRecord</span>
<span style="color: #0000ff"> write $txt</span></code>

<code>write "###############create DNS record in Azure ##########################"
<span style="color: #0000ff">New-AzureRmDnsRecordSet -Name '@' -RecordType "TXT" -ZoneName $txt.Label -ResourceGroupName $ResourceGroupName -Ttl $txt.Ttl -DnsRecords (New-AzureRmDnsRecordConfig -Value $txt.Text) -Overwrite</span></code>

<code>#Wait for DNS propagation which is very quick as inside Microsoft Network
<span style="color: #0000ff">Start-Sleep 10</span></code>

<code>write "############Confirm the DomainName is verified#############"
<span style="color: #0000ff">Confirm-MsolDomain -DomainName $DomainName -ErrorAction Continue</span></code>

<code>write "############create Exchange Office 365 DNS record in Azure##########"
#Exchange Records
<span style="color: #0000ff">$MX = $DomainName + '.mail.protection.outlook.com'</span>
<span style="color: #0000ff"> $SPF = "v=spf1 include:spf.protection.outlook.com -all"</span>
<span style="color: #0000ff"> $Auto = "autodiscover.outlook.com"</span>
<span style="color: #0000ff"> New-AzureRmDnsRecordSet -Name '@' -RecordType "MX" -ZoneName $DomainName -ResourceGroupName $ResourceGroupName -Ttl 3600 -DnsRecords (New-AzureRmDnsRecordConfig -Exchange $MX -Preference 0) -Overwrite</span>
<span style="color: #0000ff"> New-AzureRmDnsRecordSet -Name '@' -RecordType "TXT" -ZoneName $DomainName -ResourceGroupName $ResourceGroupName -Ttl 3600 -DnsRecords (New-AzureRmDnsRecordConfig -Value $SPF) -Overwrite</span>
<span style="color: #0000ff"> New-AzureRmDnsRecordSet -Name 'autodiscover' -RecordType "CName" -ZoneName $DomainName -ResourceGroupName $ResourceGroupName -Ttl 3600 -DnsRecords (New-AzureRmDnsRecordConfig -Cname $Auto) -Overwrite</span></code>

You can download this script from my <a href="https://github.com/ibenbouzid/Office365Scripts">github</a> repository which contains more options like removing your custom domain to cleanup your tenant.

Enjoy :)]]></content:encoded>
    </item>
    <item>
      <title>Hello world!</title>
      <link>https://docs.microsoft.com/archive/blogs/imadbenbouzid/hello-world</link>
      <pubDate>Wed, 22 Mar 2017 23:27:08 GMT</pubDate>
      <dc:creator><![CDATA[BharathNalla]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/imadbenbouzid/?p=1</guid>
      <description><![CDATA[Welcome to Developer Network. This is your first post. Edit or delete it, then start blogging!]]></description>
      <content:encoded><![CDATA[Welcome to <a href="https://blogs.msdn.microsoft.com/">Developer Network</a>. This is your first post. Edit or delete it, then start blogging!]]></content:encoded>
    </item>
  </channel>
</rss>