Menu Close

Microsoft TEAMS with Powershell (old method)

How-to configure direct routing

Set up of the domain, step 1

  • During the onboarding process, peoplefone will assign you a specific domain that must be configured in your O365 account.
    To configure them, go to your O365 portal, select on the left menu Setup → Domain and select Add domain
  • Enter the domain that you received from peoplefone (in this example 31857.uctrunk.com)
  • Select “Add a TXT record instead”
  • Copy-paste this screen and send it back to peoplefone so they can setup the validation 

Set up of the domain, step 2

  • When you receive the confirmation that the TXT verification is ready from peoplefone, you must go back to this domain set up and start the verification process.
    After that you must select “I’ll add the DNS records myself”
  • Disable all services and click Next
  • The domain should now be ready

Activation of the domain

  • Once the domain setup’s are completed, the next step is to activate them.
    For this, we will need to add a “dummy” user (with a E3 or E5 license) to this specific domain, not the default one.
    When the setup is completed you can delete this “dummy” user.
  • IMPORTANT: This user must have the global admin role

Assigning Global Admin to an account

Direct Routing Configuration

Please note, that enabling the rules you configure on Microsoft’s pages via PowerShell can take up to 72 hours.

This How-To covers the setup for a simple solution where only Teams is enabled as communication solution in your O365 account.
If you have or plan to have a hybrid solution with Teams and Skype for Business online or Skype, then you will need to select more parameters.
More information on:
https://docs.microsoft.com/en-us/microsoftteams/direct-routing-plan
https://docs.microsoft.com/en-us/microsoftteams/direct-routing-configure

Before starting this setup, verify that you have received the following information from peoplefone:
sbc_port
sbc_domain
sbc_nb_channels (voice channels)

In the following setup, we will use as example: (it is possible that the sbc_port is the same)
sbc_port: 6000
sbc_domain: 31857.uctrunk.com

For this setup you will need PowerShell.
The following link will provide you all information on how to install them: https://docs.microsoft.com/fr-fr/SkypeForBusiness/set-up-your-computer-for-windows-powershell/set-up-your-computer-for-windows-powershell 

  • When the PowerShell is ready, you need to load the Microsoft Teams module:
Import-Module MicrosoftTeams
  • If you get a warning that you have insufficient rights for this command, you must first execute this command:
Set-ExecutionPolicy Unrestricted
Import-Module MicrosoftTeams
  • Load the session:
Connect-MicrosoftTeams
  • A window will pop up to ask you for your credentials:
This image has an empty alt attribute; its file name is image.png
  • If you have problems setting up the session like this, then try setting up the session with the following commands:
Install-Module MicrosoftTeams
Update-Module MicrosoftTeams
$credential = Get-Credential

Connect-MicrosoftTeams -Credential $credential
$session = New-CsOnlineSession -Credential $credential
Import-PsSession $session

Verify whether the user is registered in Skype for Business Online: 

Get-CsOnlineUser -Identity “<User name>” | fl RegistrarPool

You must then receive a non-empty location.

If you have issues with the following commands below, you likely must uninstall the “Skype for Business Online, Windows Powershell Module”:

This image has an empty alt attribute; its file name is teams_new_session_commands.png

Assign ddi and EnterpriseVoice to each user with the commands:

Set-CsPhoneNumberAssignment -Identity <user@domain> -PhoneNumber +<ddi> -PhoneNumberType DirectRouting
Set-CsPhoneNumberAssignment -Identity <user@domain>  -EnterpriseVoiceEnabled $true
  • Example:
Set-CsPhoneNumberAssignment -Identity [email protected] -PhoneNumber +41582550840 -PhoneNumberType DirectRouting
Set-CsPhoneNumberAssignment -Identity [email protected]  -EnterpriseVoiceEnabled $true
  • Configure the SBC: 
New-CsOnlinePSTNGateway -Fqdn <sbc_domain> -SipSignalingPort <sbc_port> -ForwardCallHistory $true -Enabled $true -ForwardPai $true -MaxConcurrentSessions <sbc_nb_channels>
  • Example:
New-CsOnlinePSTNGateway -Fqdn 31857.uctrunk.com -SipSignalingPort 6000 -ForwardCallHistory $true -Enabled $true -ForwardPai $true -MaxConcurrentSessions 10
  • If you get the following error:
Can not use the "31857.uctrunk.com" domain as it was not configured for this tenant.
   + CategoryInfo          : InvalidArgument : (Fqdn=31857.uctr...diaBypass=False:TrunkConfig) [New-CsOnlinePSTNGateway], ArgumentException
   + FullyQualifiedErrorId : CustomValidationFailed,Microsoft.Rtc.Management.Internal.NewOnlinePSTNGatewayCmdlet
   + PSComputerName        : admin2e.online.lync.com
  • this can be due to different reasons:
    • You activated just one user on this domain and it is still not ready. You must wait – it can take a few minutes
    • You did not activate a user
    • The domain assigned to the user is not the correct one. Double check that the domain of the dummy user is the same as the sbc_domain
    • The dummy user does not have the correct license – double check that it has an E3 or E5 license.
  • Create the PstnUsage
Set-CsOnlinePstnUsage  -Identity Global -Usage @{Add="Peoplefone"}
  • Create an online route:
New-CsOnlineVoiceRoute -Identity "Peoplefone" -NumberPattern ".*" -OnlinePstnGatewayList <sbc_domain> -Priority 1 -OnlinePstnUsages "Peoplefone"
  • Example:
New-CsOnlineVoiceRoute -Identity "Peoplefone" -NumberPattern ".*" -OnlinePstnGatewayList 31857.uctrunk.com -Priority 1 -OnlinePstnUsages "Peoplefone"
  • Create the VoIP routing policy :
New-CsOnlineVoiceRoutingPolicy "Peoplefone" -OnlinePstnUsages "Peoplefone"
  • Grant this VoIP routing policy to the user:
Grant-CsOnlineVoiceRoutingPolicy -Identity "<user>" -PolicyName "Peoplefone"
  • Example:
Grant-CsOnlineVoiceRoutingPolicy -Identity "[email protected]" -PolicyName "Peoplefone"

If you get an error, saying that the policy cannot be applied, this user needs to login one time into the team client

Set Teams as preferred calling client: (needed if account was migrated from Skype to Teams)

Get-CsOnlineUser <user>| Select Teams*
TeamsMeetingPolicy :
TeamsCallingPolicy: AllowCalling
TeamsInteropPolicy: DisallowOverrideCallingTeamsChatTeams
TeamsMessagingPolicy :
TeamsUpgradeEffectiveMode : Islands
TeamsUpgradeNotificationsEnabled : False
TeamsUpgradePolicyIsReadOnly : None
TeamsUpgradePolicy :
TeamsCortanaPolicy :
TeamsOwnersPolicy :
TeamsMeetingBroadcastPolicy :
TeamsUpgradeOverridePolicy :
TeamsVideoInteropServicePolicy :
TeamsWorkLoadPolicy :

Check and fix the Interop Policy & Calling Policy

Grant-CsTeamsUpgradePolicy -PolicyName DisallowOverrideCallingTeamsChatTeams -Identity <user@domain>
Grant-CsTeamsCallingPolicy -PolicyName AllowCalling -Identity <user@domain>

Example for how to set a specific user as Anonymous:

  • Create an anonymous policy:
New-CsCallingLineIdentity  -Identity Anonymous -Description "Anonymous policy" -CallingIDSubstitute Anonymous -EnableUserOverride $false
  • Assign the policy to the user:
Grant-CsCallingLineIdentity -Identity "<user>" -PolicyName Anonymous

PowerShell Command for an overview of the configuration of a single user

Get-CsOnlineUser -Identity "<identity>" | Format-List -Property FirstName, LastName, EnterpriseVoiceEnabled, HostedVoiceMail, LineURI, UsageLocation, UserPrincipalName, WindowsEmailAddress, SipAddress, OnPremLineURI, OnlineVoiceRoutingPolicy

Other Information

How can a caller ID be used in your organization?
https://docs.microsoft.com/en-us/SkypeForBusiness/what-are-calling-plans-in-office-365/how-can-caller-id-be-used-in-your-organization

Setting the Caller ID for a user:
https://docs.microsoft.com/en-us/skypeforbusiness/what-are-calling-plans-in-office-365/set-the-caller-id-for-a-user

References

This How-To is based on the Microsoft documentation version published 27.06.2018 (GA)
You can find more info on the following links:
https://docs.microsoft.com/en-us/microsoftteams/direct-routing-plan
https://docs.microsoft.com/en-us/microsoftteams/direct-routing-configure
https://docs.microsoft.com/en-us/microsoftteams/onboarding-checklist-configure-direct-routing-in-microsoft-teams