Setting up Microsoft Teams for Direct Routing
Created: 2020-07-08 00:23:45 | Last modified: 2020-07-31 04:30:44
Access: Read | Views: 662 | Rating: N/A | Tags:
Instructions of how to setup a Microsoft Teams carrier tenant for direct routing of calls
Microsoft teams has the ability to use an external PBX for external call routing. This maybe required in countries where Microsoft doesn't have a PSTN pressence, or you might want calls to go through your local PBX. In most cases you will require an SBC (Session Boarder Controller) which will connection Microsoft Teams to our PBX or SIP provider. We have decided to go with Anynode (https://www.anynode.de/) as their SBC is software based, runs on Linux Debian and is Microsoft certified. They also offer a free trial to get the SBC up and running.
To use Direct Routing which is the Microsoft preferred way of providing calls over a single trunk we will need to create a carrier tenant. Much of the stuff here is done inside Power Shell so make yourself familiar with this before you start.
First download the Skype Power Shell module (this allows an interface into Teams). Make sure you have a created a carrier tenant inside the microsoft admin portal. You will need to add the domains and assign an E1, E3 or E5 license to the admin user. You will also need one spare to assign to a tempuary user if teams doesn't allow a PSTN gateway to be added (later in this document)
Download and install the "Skype for Business Online, Windows PowerShell Module" from https://www.microsoft.com/en-us/download/details.aspx?id=39366
Open Powershell
# Import the module
Import-Module SkypeOnlineConnector
Connect to Teams
$teamssession = New-CsOnlineSession -UserName [email protected]
Import-PSSession $teamssession -AllowClobber
Creating A Carrier Tenant
Create the PSTN Gateway
# Check PSTN Gateway available
Get-Command *onlinePSTNGateway
# Confirm domains are avaialble
Get-CsOnlineSipDomain
# Check and set SBC gateway. If this doesn't work, see Appendix 1 below;
Get-CsOnlinePSTNGateway -identity "sbc1.customer.yourcarrier.com"
New-CsOnlinePSTNGateway
# Port 5067
# Identity sbc1.customer.yourcarrier.com
# Modify inside tenancy inside 365 for the:
- Enabled: true
- Forward Call History: true
- Concurrent Call Capcity: 60
# Update the PSTN Gateway if required, we enabled ForwardPai
Set-CsOnlinePSTNGateway -identity "sbc1.customer.yourcarrier.com" -ForwardPai $true

Set a default user
# Set Default User
Set-CsUser -Identity "[email protected] " -EnterpriseVoiceEnabled $true -HostedVoiceMail $true
# Set PSTN Usage
Set-CsOnlinePstnUsage -Identity "Global" -Usage "YourVOIP"
Get-CsOnlinePstnUsage
# Set voice route
New-CsOnlineVoiceRoute -Identity "YourVOIP" -NumberPattern ".*" -OnlinePstnUsages "YourVOIP" -OnlinePstnGatewayList "sbc1.customer.yourcarrier.com"
# Set voice routing policy
New-CsOnlineVoiceRoutingPolicy -Identity "YourVOIP" -OnlinePstnUsages "YourVOIP"
# Grant Policy
Grant-CsOnlineVoiceRoutingPolicy -PolicyName "YourVOIP"
Adding A Client
Now you need to add a client which will use the carrier trunk
Config process
- Users must be assigned an E1, E3 or E5 license and a phone system license if E1 or E3
- Create xxx.sbc1.customer.yourcarrier.com domain in client microsoft tenancy
- Activate domain by creating/assigning user to this domain xxxx.sbc1.customer.yourcarrier.com (required see Appendix 1)
- Add txt record to confirm
# Add voice route inside powershell, so connect
$teamssession = New-CsOnlineSession -UserName [email protected]
Import-PSSession $teamssession -AllowClobber
#Create Policy
New-CsOnlineVoiceRoutingPolicy -Identity "YourVOIP"
# Enable users for direct routing
Set-CsUser -Identity "[email protected]" -OnPremLineURI tel:+123456789 -EnterpriseVoiceEnabled $true -HostedVoiceMail $true
# Confirm user is enabled
Get-CsOnlineUser -Identity "[email protected]" | fl RegistrarPool
# Grant the voice routing policy
Grant-CsOnlineVoiceRoutingPolicy -Identity "[email protected]" -PolicyName "YourVOIP"
# Confirm policy has been granted
Get-CsOnlineUser -Identity "[email protected]" | fl OnlineVoiceRoutingPolicy
OnlineVoiceRoutingPolicy : YourVOIP
# Confirm User has a hosting provider and is homed in Skype
Get-CsOnlineUser -Identity "[email protected]" | fl HostingProvider, RegistrarPool
HostingProvider : sipfed.online.lync.com
RegistrarPool : sippoolsy3au103.infra.lync.com
#Set the Online PSTN Carier
Set-CsOnlinePstnUsage -Identity Global -Usage @{Add="YourVOIP"}
# Set the online route (note took time when user for tenant.sbc1.c... was added)
New-CsOnlineVoiceRoute -Identity "YourVOIP" -NumberPattern ".*" -OnlinePstnGatewayList "tenant.sbc1.customer.yourcarrier.com" -OnlinePstnUsages "YourVOIP"
#Set the policy
New-CsOnlineVoiceRoutingPolicy "YourVOIP" -OnlinePstnUsages "YourVOIP"
Add another user
### New User (Example - user2)
Set-CsUser -Identity "[email protected]" -OnPremLineURI tel:223456789-EnterpriseVoiceEnabled $true -HostedVoiceMail $true
# Confirm added
Get-CsOnlineUser -Identity "[email protected]" | fl RegistrarPool
# Grant permissions
Grant-CsOnlineVoiceRoutingPolicy -Identity "[email protected]" -PolicyName "YourVOIP"
# Confirm Users are inside register pool and active
Get-CsOnlineUser -Identity "[email protected]" | fl OnlineVoiceRoutingPolicy
Get-CsOnlineUser -Identity "[email protected]" | fl HostingProvider, RegistrarPool
Appendix 1
If When trying to add PSTN Gateway I get the following. "Can not use the "sbc1.customer.yourdomain.com" domain as it was not configured for this tenant"
$FormatEnumerationLimit =-1
Get-CsTenant | fl Tenantid,Domain*
TenantId : 6d35e876-3a61-4a45-a97f-e0af00eba4db
Domains : {tenant.sbc1.customer.yourdomain.com, sbc1.customer.yourdomain.com, customer.yourdomain.com,
yourdomain.onmicrosoft.com}
DomainUrlMap : {yourdomain.onmicrosoft.com}
You are missing Missing the SBC in the DomainUrlMap
Fix
Create a Global Admin with the domain suffix
Create a Global Admin account in Cloud (not synced with AADC) with a UPN @yourdomaindomain.com and not @yourdomain.onmicrosoft.com, assign a E1, E3 or E5 Licence, wait 24 hours, when you run the Get-CsTenant command again you should see the domain inside the list. You can then remove the newly created and the license
Result after 24 hours (was 30 mins in my case)
$FormatEnumerationLimit =-1
Get-CsTenant | fl Tenantid,Domain*
TenantId : 6d35e876-3a61-4a45-a97f-e0af00eba4db
Domains : {tenant.sbc1.customer.yourdomain.com, sbc1.customer.yourdomain.com, customer.yourdomain.com,
yourdomain.onmicrosoft.com}
DomainUrlMap : {yourdomain.onmicrosoft.com, sbc1.customer.yourdomain.com}