VoIP:Teams:Microsoft Management: Difference between revisions

From VTX Public Wiki

(Switch to version 2.0.0 of MicrosoftTeams module)
Line 140: Line 140:


# Set Variables
# Set Variables
$MSTeamsDomain = '''"123456.teams.ipvoip.ch"'''
$TeamsDomain = '''"123456.teams.ipvoip.ch"'''
$MSTeamsUserEmail = "'''first.last@MSDOMAIN.onmicrosoft.com'''"
$TeamsUserEmail = "'''first.last@MSDOMAIN.onmicrosoft.com'''"
$MSTeamsUserNumber = '''"+41215661234"'''
$TeamsUserNumber = '''"+41215661234"'''
# Connect to Microsoft Teams management and assign number and profile to the user
# Connect to Microsoft Teams management and assign number and profile to the user
Connect-MicrosoftTeams
Connect-MicrosoftTeams
# Assign a number to your user and the Call Routing
# Assign a number to your user and the Call Routing
Set-CsPhoneNumberAssignment -Identity "$TeamsUserEmail" -PhoneNumber "$TeamsUserNumber" -PhoneNumberType DirectRouting
Set-CsUser -Identity $MSTeamsUserEmail -EnterpriseVoiceEnabled $true -OnPremLineURI "tel:$MSTeamsUserNumber"
# Assign a Voice Routing Policy to your user to allow it to call out towards external numbers
# Assign a Voice Routing Policy to your user to allow it to call out towards external numbers
Grant-CsOnlineVoiceRoutingPolicy -Identity $MSTeamsUserEmail -PolicyName "CsOnlineVoiceRoutingPolicy-$MSTeamsDomain"
Grant-CsOnlineVoiceRoutingPolicy -Identity $MSTeamsUserEmail -PolicyName "CsOnlineVoiceRoutingPolicy-$MSTeamsDomain"
Line 156: Line 156:
Get-CsOnlineUser -Identity $MSTeamsUserEmail | Select EnterpriseVoiceEnabled,OnPremLineURI,OnlineVoiceRoutingPolicy,RegistrarPool | Format-List
Get-CsOnlineUser -Identity $MSTeamsUserEmail | Select EnterpriseVoiceEnabled,OnPremLineURI,OnlineVoiceRoutingPolicy,RegistrarPool | Format-List
# List all users with EnterPrise Voice Enabled
# List all users with EnterPrise Voice Enabled
Get-CsOnlineUser ` -Filter {(enterprisevoiceenabled -eq $true) -and(HostingProvider -eq "sipfed.online.lync.com")} ` | Select sipaddress,HostedVoicemailPolicy,OnlineVoiceRoutingPolicy,lineuri,OnPremLineURI,RegistrarPool | Format-List
Get-CsOnlineUser ` -Filter {(enterprisevoiceenabled -eq $true)} ` | Select sipaddress,HostedVoicemailPolicy,OnlineVoiceRoutingPolicy,lineuri | Format-List
# Logout
# Logout
Disconnect-MicrosoftTeams
Disconnect-MicrosoftTeams

Revision as of 12:54, 1 July 2022

Connect to Microsoft 365 Admin Portal[edit | edit source]

Create a temporarily user in the <servicenumber>.teams.ipvoip.ch domain[edit | edit source]


  • Problematic: We wish to create a enableteams@<servicenumber>.teams.ipvoip.ch to enable Teams connection towards VTX VoIP platform
  • Solution: Please follow the procedure below
  1. Connect to https://admin.microsoft.com/Adminportal/Home#/users
  2. Create a new user enableteams@<servicenumber>.teams.ipvoip.ch ( First Name: "Temp User" / Last Name : "VTX Teams" / Login : enableteams@<servicenumber>.teams.ipvoip.ch / No Admin Right / "Teams" and "Phone System" licenses / No need to remember its password, we won't connect with it).
  3. Wait a few seconds/minutes/hours for Teams to be enabled on this user https://admin.microsoft.com/AdminPortal/Home#/teamsprovisioning
  4. Now even after user is created you night need to wait minutes/hours before being able to create Voice Routing ( especially the New-CsOnlineVoiceRoute ), so if you can please wait 4hours, if not, try to create the routing, if you get error, try again
  5. Once everything is working ( routing + user mapping + incoming and outgoing calls ), you can delete this user to free up the licenses

Voice Routing : Create Voice Routing to allow your users to use VTX Trunk[edit | edit source]

Now you will need to setup a routing plan. You can use one of the following options to do it

  • Using a Powershell Script that will ask you questions
  • Manually in Powershell


Microsoft Admin Center - Up to 24h Latency for each setup


Create Voice Routing using a VTX Powershell Script VTX_Teams_Create_Routing_Rules.ps1[edit | edit source]


  1. Download https://wiki.vtx.ch/media/VTX_Teams_Create_Routing_Rules.ps1 on your computer ( Right Click on the link / Download )
  2. Open it with Wordpad and use Ctrl-s to save it again ( to inform the system that it is local script )
  3. Execute it on your PC : It will ask you for these parameters and create the routing
    1. VTX Teams Domain : ex: 123456.teams.ipvoip.ch
    2. Your MS Teams Admin Credentials : ex: admin@COMPANY.onmicrosoft.com

Or Create Voice Routing manually in Powershell Command Prompt[edit | edit source]


  1. Open a powershell prompt on your PC
  2. Copy paste command below one by one changing the values in bold with your own
# Set Variables
$MSTeamsDomain = "123456.teams.ipvoip.ch"
# Connect to Microsoft Teams management and create all Voice Routing
Connect-MicrosoftTeams
Set-CsOnlinePstnUsage -Identity Global -Usage @{Add="CsOnlinePstnUsage-$MSTeamsDomain"}
New-CsOnlineVoiceRoute -Identity "CsOnlineVoiceRoute-$MSTeamsDomain" -Priority 0 -NumberPattern '.*' -OnlinePstnGatewayList "$MSTeamsDomain" -OnlinePstnUsages "CsOnlinePstnUsage-$MSTeamsDomain"
New-CsOnlineVoiceRoutingPolicy -Identity "CsOnlineVoiceRoutingPolicy-$MSTeamsDomain" -OnlinePstnUsages "CsOnlinePstnUsage-$MSTeamsDomain"
Set-CsCallingLineIdentity -Identity Global -EnableUserOverride $True

# Verify all setup ( You can compare it with the Debug Section in the wiki ) 
Get-CsOnlinePstnUsage
Get-CsOnlineVoiceRoute
Get-CsOnlineVoiceRoutingPolicy
Get-CsCallingLineIdentity

# Logout
Disconnect-MicrosoftTeams

Number Mapping : Assign numbers to Microsoft accounts[edit | edit source]

Now you will need to assign a number and a routing plan to each user with a "Microsoft 365 Phone System" license. You can use one of the following options to do it

  • Using a Powershell Script that will ask you questions
  • Manually in Powershell


Assign numbers using a VTX Powershell Script VTX_Teams_Assign_Numbers.ps1[edit | edit source]

  1. Download https://wiki.vtx.ch/media/VTX_Teams_Assign_Numbers.ps1 on your computer ( Right Click on the link / Download )
  2. Open it with Wordpad and use Ctrl-s to save it again ( to inform the system that it is local script )
  3. Execute it on your PC : It will ask you for these parameters and create the routing
    1. VTX Teams Domain : ex: 123456.teams.ipvoip.ch
    2. Your MS Admin Credentials for : ex: admin@MSDOMAIN.onmicrosoft.com
    3. The MS Team user email : ex: first.last@MSDOMAIN.onmicrosoft.com
    4. The Telephone number you wish to set : ex: +41225661234


Here is a list of screenshots to see how the script works

Teams Assignment - 1st Warning - Is routing OK ?
Teams Assignment - Enter the Teams Domain Provided by VTX
Teams Assignment - Enter Teams Admin email
Teams Assignment - Enter Teams User Email
Teams Assignment - Enter Teams User Phone Number
Teams Assignment - Disable voicemail on the user ?
Teams Assignment - Setup another user ?
Teams Assignment - List all user setup ?
Teams Assignment - 1st Warning - Is routing OK ?

Or Assign numbers manually in Powershell Command Prompt[edit | edit source]

  1. Open a powershell prompt on your PC
  2. Copy paste command below one by one changing the values in bold with your own
# Set Variables
$TeamsDomain = "123456.teams.ipvoip.ch"
$TeamsUserEmail = "first.last@MSDOMAIN.onmicrosoft.com"
$TeamsUserNumber = "+41215661234"
# Connect to Microsoft Teams management and assign number and profile to the user
Connect-MicrosoftTeams
# Assign a number to your user and the Call Routing
Set-CsPhoneNumberAssignment -Identity "$TeamsUserEmail" -PhoneNumber "$TeamsUserNumber" -PhoneNumberType DirectRouting
# Assign a Voice Routing Policy to your user to allow it to call out towards external numbers
Grant-CsOnlineVoiceRoutingPolicy -Identity $MSTeamsUserEmail -PolicyName "CsOnlineVoiceRoutingPolicy-$MSTeamsDomain"
# Disable voicemail of the user to prevent that it answers all calls if user is not connected
Set-CsOnlineVoicemailUserSettings -Identity $MSTeamsUserEmail -VoicemailEnabled $false
# Wait 60s for settings to be applied
Sleep -s 60
# Verify Your setup 
Get-CsOnlineUser -Identity $MSTeamsUserEmail | Select EnterpriseVoiceEnabled,OnPremLineURI,OnlineVoiceRoutingPolicy,RegistrarPool | Format-List
# List all users with EnterPrise Voice Enabled
Get-CsOnlineUser ` -Filter {(enterprisevoiceenabled -eq $true)} ` | Select sipaddress,HostedVoicemailPolicy,OnlineVoiceRoutingPolicy,lineuri | Format-List
# Logout
Disconnect-MicrosoftTeams