Direct Routing Setup v2 - Updated 2026

6 min. readlast update: 03.11.2026

There is an updated document for Microsoft Teams.

If you are an existing client who already has Microsoft Teams installed, please do not use this document, as it is intended for new installations only. Microsoft has updated the backend configuration for new clients, which differs from the version you are currently using.

Clients who implemented Teams prior to 2026 should use the link below.

Prior to 2026

 

Step 1: Add and Verify Domain

Web Portal

  1. Go to Microsoft 365 Admin Center (admin.microsoft.com)
  2. Navigate to Settings → Domains → Add domain
  3. Enter domain name (e.g., yourcompany.key2pbx.ca)
  4. Add the provided DNS TXT record to your domain registrar
  5. Wait 15-30 minutes for DNS propagation
  6. Click Verify

Step 2: Configure Session Border Controller (SBC)

Web Portal

  1. Go to Teams Admin Center (admin.teams.microsoft.com)
  2. Navigate to Voice → Direct Routing → SBCs
  3. Click + Add
  4. Configure:
    • FQDN: yourcompany.key2pbx.ca
    • Enabled: On
    • SIP signaling port: 5061
    • Max concurrent sessions: 100
  5. Click Save

PowerShell

connect to your tenant

# Connect using device code authentication
Connect-MicrosoftTeams -UseDeviceAuthentication

# Verify connection
$connectionInfo = Get-CsTenant -ErrorAction Stop
Write-Host "Connected to tenant: $($connectionInfo.DisplayName)"

 

$sbcFqdn = "yourcompany.key2pbx.ca"
$sipPort = 5061
$maxConcurrentSessions = 100

# Check if SBC exists
$existingSbc = Get-CsOnlinePSTNGateway -Identity $sbcFqdn -ErrorAction SilentlyContinue

if ($existingSbc) {
    # Update existing SBC
    Set-CsOnlinePSTNGateway -Identity $sbcFqdn -SipSignalingPort $sipPort -MaxConcurrentSessions $maxConcurrentSessions -Enabled $true
} else {
    # Create new SBC
    New-CsOnlinePSTNGateway -Fqdn $sbcFqdn -SipSignalingPort $sipPort -MaxConcurrentSessions $maxConcurrentSessions -Enabled $true
}

# Verify configuration
$sbcConfig = Get-CsOnlinePSTNGateway -Identity $sbcFqdn
Write-Host "FQDN: $($sbcConfig.Fqdn)"
Write-Host "SIP Port: $($sbcConfig.SipSignalingPort)"
Write-Host "Max Sessions: $($sbcConfig.MaxConcurrentSessions)"
Write-Host "Enabled: $($sbcConfig.Enabled)"

 

Step 4: Create PSTN Usage

Web Portal

  1. Go to Teams Admin Center → Voice → Direct Routing
  2. Click Voice routing policies tab → PSTN usage records tab
  3. Click + Add
  4. Enter name: "key2PSTNUsage"
  5. Click Save

Powershell

$pstnUsageName = "key2PSTNUsage"

# Check if usage exists
$currentUsage = Get-CsOnlinePstnUsage

if ($currentUsage.Usage -contains $pstnUsageName) {
    Write-Host "PSTN Usage $pstnUsageName already exists."
} else {
    Write-Host "Creating PSTN Usage..."
    Set-CsOnlinePstnUsage -Identity Global -Usage @{Add=$pstnUsageName}
}

 

Step 5: Create Voice Route

Web Portal

  1. Go to Voice → Direct Routing → Voice routes
  2. Click + Add
  3. Configure:
    • Name: key2-Outbound-Route
    • Dialed number pattern.* (matches all calls)
    • Priority: 1
    • PSTN usage: key2PSTNUsage
    • SBCs: yourcompany.key2pbx.ca
  4. Click Save

Powershell

$routeName = "key2-Outbound-Route"
$routePattern = ".*"
$sbcFqdn = "yourcompany.key2pbx.ca"
$pstnUsageName = "key2PSTNUsage"

# Remove existing route if it exists
$existingRoute = Get-CsOnlineVoiceRoute -Identity $routeName -ErrorAction SilentlyContinue
if ($existingRoute) {
    Remove-CsOnlineVoiceRoute -Identity $routeName -Confirm:$false
}

# Create voice route with priority 1
New-CsOnlineVoiceRoute -Identity $routeName -NumberPattern $routePattern -OnlinePstnGatewayList $sbcFqdn -OnlinePstnUsages $pstnUsageName -Priority 1

# Verify and update priority if needed
Start-Sleep -Seconds 2
$verifyRoute = Get-CsOnlineVoiceRoute -Identity $routeName
if ($verifyRoute.Priority -ne 1) {
    Set-CsOnlineVoiceRoute -Identity $routeName -Priority 1 -Confirm:$false
}

# Ensure this route has highest priority
$allRoutes = Get-CsOnlineVoiceRoute
$otherPriority1Routes = $allRoutes | Where-Object { $_.Identity -ne $routeName -and $_.Priority -le 1 }

if ($otherPriority1Routes) {
    $counter = 2
    foreach ($route in $otherPriority1Routes) {
        Set-CsOnlineVoiceRoute -Identity $route.Identity -Priority $counter -Confirm:$false
        $counter++
    }
}

# Verify and Display configuration
$route = Get-CsOnlineVoiceRoute -Identity $routeName
Write-Host "Identity: $($route.Identity)"
Write-Host "Number Pattern: $($route.NumberPattern)"
Write-Host "Gateway: $($route.OnlinePstnGatewayList)"
Write-Host "Priority: $($route.Priority)"

 

Step 6: Create Voice Routing Policy

Web Portal

  1. Go to Voice → Voice routing policies
  2. Click + Add
  3. Configure:
    • Name: key2-Voice-Policy
    • PSTN usage records: Add "key2PSTNUsage"
  4. Click Save

Powershell

$policyName = "key2-Voice-Policy"
$pstnUsageName = "key2PSTNUsage"

# Check if policy exists
$existingPolicy = Get-CsOnlineVoiceRoutingPolicy -Identity $policyName -ErrorAction SilentlyContinue

if ($existingPolicy) {
    # Update existing policy
    Set-CsOnlineVoiceRoutingPolicy -Identity $policyName -OnlinePstnUsages @{Add=$pstnUsageName}
} else {
    # Create new policy
    New-CsOnlineVoiceRoutingPolicy -Identity $policyName -OnlinePstnUsages $pstnUsageName
}

# Verify and Display configuration
$policy = Get-CsOnlineVoiceRoutingPolicy -Identity $policyName
Write-Host "Identity: $($policy.Identity)"
Write-Host "PSTN Usages: $($policy.OnlinePstnUsages -join ', ')"

Step 7: Assign Phone Numbers to Users

Web Portal

  1. Go to Teams Admin Center → Users → Manage users
  2. Select a user → Account tab
  3. Under Phone number, click Edit
  4. Configure:
    • Phone number type: Direct Routing
    • Phone number: +12065551234 (E.164 format) or extension (e.g., 1001)
  5. Click Save

Powershell

$userPrincipalName = "user@yourcompany.com"
$phoneNumber = "+14165551234"  # or extension like "1001"

# Check if user exists
$existingUser = Get-CsOnlineUser -Identity $userPrincipalName -ErrorAction SilentlyContinue

if ($existingUser) {
    # Assign phone number
    Set-CsPhoneNumberAssignment -Identity $userPrincipalName -PhoneNumber $phoneNumber -PhoneNumberType DirectRouting
    Write-Host "Phone number assigned"
}

Powershell

$userPrincipalName = "user@yourcompany.com"
$phoneNumber = "+12065551234"  # or extension like "1001"

# Check if user exists
$existingUser = Get-CsOnlineUser -Identity $userPrincipalName -ErrorAction SilentlyContinue

if ($existingUser) {
    # Assign phone number
    Set-CsPhoneNumberAssignment -Identity $userPrincipalName -PhoneNumber $phoneNumber -PhoneNumberType DirectRouting
    Write-Host "Phone number assigned"
}

Step 8: Enable Enterprise Voice

note

Enterprise Voice cannot be enabled through the web portal. Must use PowerShell.

Powershell

$userPrincipalName = "user@yourcompany.com"

# Enable Enterprise Voice
Set-CsUser -Identity $userPrincipalName -EnterpriseVoiceEnabled $true
Write-Host "Enterprise Voice enabled"

 

Step 9: Assign Voice Routing Policy

Web Portal

  1. Go to Users → Manage users
  2. Select user → Policies tab
  3. Under Voice routing policy, select "key2-Voice-Policy"
  4. Click Save

Powershell

$userPrincipalName = "user@yourcompany.com"
$policyName = "key2-Voice-Policy"

# Assign voice routing policy
Grant-CsOnlineVoiceRoutingPolicy -Identity $userPrincipalName -PolicyName $policyName
Write-Host "Voice routing policy assigned"

 

Step 10: Verify User Configuration

Web Portal

  1. Go to Users → Manage users → Select user
  2. Check Account tab:
    • Phone number is assigned
    • Phone number type shows "Direct Routing"
  3. Check Policies tab:
    • Voice routing policy is assigned

Powershell

$userPrincipalName = "user@yourcompany.com"

# Verify user configuration
$userConfig = Get-CsOnlineUser -Identity $userPrincipalName | Select-Object UserPrincipalName, LineUri, EnterpriseVoiceEnabled, OnlineVoiceRoutingPolicy

Write-Host "User: $($userConfig.UserPrincipalName)"
Write-Host "Phone Number: $($userConfig.LineUri)"
Write-Host "Enterprise Voice: $($userConfig.EnterpriseVoiceEnabled)"
Write-Host "Voice Policy: $($userConfig.OnlineVoiceRoutingPolicy)"

 

Complete Configuration (Full User Setup) via Powershell commands

PowerShell - Complete User Configuration

# Connect
Connect-MicrosoftTeams -UseDeviceAuthentication
$connectionInfo = Get-CsTenant -ErrorAction Stop

# Define variables
$userPrincipalName = "user@yourcompany.com
$phoneNumber = "+4165551234"  # or extension like "1001"
$policyName = "key2-Voice-Policy"

# Check user exists
$existingUser = Get-CsOnlineUser -Identity $userPrincipalName -ErrorAction SilentlyContinue

if ($existingUser) {
    # Assign phone number
    Set-CsPhoneNumberAssignment -Identity $userPrincipalName -PhoneNumber $phoneNumber -PhoneNumberType DirectRouting
    
    # Enable Enterprise Voice
    Set-CsUser -Identity $userPrincipalName -EnterpriseVoiceEnabled $true
    
    # Assign voice routing policy
    Grant-CsOnlineVoiceRoutingPolicy -Identity $userPrincipalName -PolicyName $policyName
    
    # Verify configuration
    $userConfig = Get-CsOnlineUser -Identity $userPrincipalName | Select-Object UserPrincipalName, LineUri, EnterpriseVoiceEnabled, OnlineVoiceRoutingPolicy
    
    #diaply stored data 
    Write-Host "User: $($userConfig.UserPrincipalName)"
    Write-Host "Phone Number: $($userConfig.LineUri)"
    Write-Host "Enterprise Voice: $($userConfig.EnterpriseVoiceEnabled)"
    Write-Host "Voice Policy: $($userConfig.OnlineVoiceRoutingPolicy)"
}

# Disconnect
Disconnect-MicrosoftTeams

Troubleshooting

User Can't Make Calls

# Verify user configuration
Get-CsOnlineUser -Identity user@yourcompany.com | Select-Object LineUri, EnterpriseVoiceEnabled, OnlineVoiceRoutingPolicy

 

Was this article helpful?