Powershell to provision Office 365 Tenant

Please refer to the following steps on how to use Powershell to provision Office 365 Tenant

  1. Go to Office 365 DEMO and sign up for 90 Days Trial Account if you are Microsoft Partner
  2. Download Microsoft Online Services Sign-in Assistant for IT Professionals RTW-msoidcli_64.msi and install it
  3. Install Nuget Provider – Internet Connection is required
Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force

Install-Module MSOnline

Install-Module MsOnline 
$UserName = "[email protected]"
#"xxxxxxx" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\scripts\Password.txt"
$Password = Get-Content "C:\Scripts\Password.txt" | ConvertTo-SecureString

#Specify Credential with password 
$Credential = new-object -typename System.Management.Automation.PSCredential -ArgumentList $UserName,$Password

Connect-MsolService -Credential $Credential

Connect to Exchange Online
Please refer to the script below on how to connect to Exchange Online

#Change the Execution Policy to RemoteSigned 
Set-ExecutionPolicy RemoteSigned -Force

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
-Credential $Credential -Authentication  Basic -AllowRedirection

Import-PSSession $Session

Common Tasks for initial Office 365 Setup
Verify the license purchased

Get-MsolAccountSku

AccountSkuId                  ActiveUnits WarningUnits ConsumedUnits
------------                  ----------- ------------ -------------
M365x447354:WIN10_VDA_E5      25          0            1            
M365x447354:EMSPREMIUM        100         0            1            
M365x447354:ENTERPRISEPREMIUM 25          0            1        

Associate Public DNS Domain

$FQDN="AventisLab.com"
New-MsolDomain -Name $FQDN
Get-MsolDomainVerificationDns -DomainName $FQDN -Mode DnsTxtRecord

Add the TXT record to your public DNS Server

#Verify the TXT Record had been updated 
nslookup -type=TXT AventisLab.com

    nslookup -type=TXT AventisLab.com
    Server:  huddle
    Address:  2402:b400:40c0:177d:5865:e6ff:fe38:4c0f

    aventislab.com  text =

        "MS=ms52173542"

#Comfirm the Domain 
Confirm-MsolDomain -DomainName $FQDN

Get-MsolDomain
Name                        Status   Authentication
----                        ------   --------------
M365x447354.onmicrosoft.com Verified Managed       
AventisLab.com              Verified Managed  

Set the Public FQDN as Primary

Set-MsolDomain -Name $FQDN -IsDefault

Reference Link
1. Connect to Office 365 PowerShell

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top