forked from leeford/Test-CSOnlineUserVoiceRouting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test-CSOnlineUserVoiceRouting.ps1
177 lines (108 loc) · 5.75 KB
/
Test-CSOnlineUserVoiceRouting.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<#
.SYNOPSIS
Test-CSOnlineUserVoiceRouting.ps1 - Test a user's Online Voice Routing Policy for Teams Direct Routing
.DESCRIPTION
Author: Lee Ford
Using this script you can test a user's assigned Online Voice Routing Policy - this policy is used to decide how to route Direct Routing calls.
Simply provide a dialed number and a user to see what Voice Routes would be used and in what order.
For more information, go to https://wp.me/p97Bkx-g5
.LINK
Blog: https://www.lee-ford.co.uk
Twitter: http://www.twitter.com/lee_ford
LinkedIn: https://www.linkedin.com/in/lee-ford/
.EXAMPLE
.\Test-CSOnlineUserVoiceRouting.ps1 -DialedNumber +441234567890 -User [email protected]
This will list any Voice Routes (in priority order) for [email protected] calling +441234567890
#>
param(
[Parameter(mandatory = $true)][String]$User,
[Parameter(mandatory = $true)][String]$DialedNumber,
[Parameter(mandatory = $false)][string]$OverrideAdminDomain
)
function Check-ModuleInstalled {
param (
[Parameter (mandatory = $true)][String]$module,
[Parameter (mandatory = $true)][String]$moduleName
)
# Do you have module installed?
Write-Host "`nChecking $moduleName installed..." -NoNewline
if (Get-Module -ListAvailable -Name $module) {
Write-Host " INSTALLED" -ForegroundColor Green
}
else {
Write-Host " NOT INSTALLED" -ForegroundColor Red
break
}
}
function Test-TeamsConnection {
if(-not((Get-Command Get-CsTeamsCallingPolicy -ErrorAction "SilentlyContinue") -and (Get-CsTeamsCallingPolicy -ErrorAction "SilentlyContinue"))){
return $false
}
return $true
}
# Start
Write-Host "`n----------------------------------------------------------------------------------------------
`n Test-CSOnlineUserVoiceRouting.ps1 - Lee Ford - https://www.lee-ford.co.uk
`n----------------------------------------------------------------------------------------------" -ForegroundColor Yellow
Write-Host "`nChecking voice routing of dialed number $DialedNumber for $user" -ForegroundColor Yellow
# Check Teams module installed
Check-ModuleInstalled -module MicrosoftTeams -moduleName "Microsoft Teams module"
if (-not(Test-TeamsConnection)) {
Write-Host "No existing PowerShell Session..."
Connect-MicrosoftTeams
}
else {
Write-Host "Using existing PowerShell Session..."
}
$VoiceRoutes = @()
$MatchedVoiceRoutes = @()
# Check if user exists
$UserReturned = Get-CSOnlineUser -Identity $User -ErrorAction SilentlyContinue
if ($UserReturned) {
# Get effective dial plan for user, then test it and return normalised number (if needed) along with the matched rule
Write-Host "`nGetting Effective Tenant Dial Plan for $user and translating number..."
$EffectiveDialPlan = Get-CsEffectiveTenantDialPlan -Identity $user
$NormalisedResult = $EffectiveDialPlan | Test-CsEffectiveTenantDialPlan -DialedNumber $DialedNumber
if ($NormalisedResult.TranslatedNumber) {
Write-Host "`r$DialedNumber translated to $($NormalisedResult.TranslatedNumber)" -ForegroundColor Green
Write-Host "`r(Using rule:`n$($NormalisedResult.MatchingRule -replace ";", "`n"))"
$NormalisedNumber = $NormalisedResult.TranslatedNumber
}
else {
Write-Host "`rNo translation patterns matched"
$NormalisedNumber = $DialedNumber
}
# Get the Online Voice Routing Policy assigned to the user
Write-Host "`nGetting assigned Online Voice Routing Policy for $User..."
[string]$UserOnlineVoiceRoutingPolicy = (Get-CsUserPolicyAssignment -Identity $User -PolicyType OnlineVoiceRoutingPolicy).PolicyName
if ($UserOnlineVoiceRoutingPolicy) {
Write-Host "`rOnline Voice Routing Policy assigned to $user is: '$UserOnlineVoiceRoutingPolicy'" -ForegroundColor Green
# Get PSTN Usages assigned to Online Voice Routing Policy
$PSTNUsages = (Get-CsOnlineVoiceRoutingPolicy -Identity $UserOnlineVoiceRoutingPolicy).OnlinePstnUsages
# Loop through each PSTN Usage and get the Voice Routes
foreach ($PSTNUsage in $PSTNUsages) {
$VoiceRoutes += Get-CsOnlineVoiceRoute | Where-Object { $_.OnlinePstnUsages -contains $PSTNUsage } | Select-Object *, @{label = ”PSTNUsage”; Expression = { $PSTNUsage } }
}
# Find PSTN first matching PSTN Usage
Write-Host "`nFinding the first PSTN Usage with a Voice Route that matches $NormalisedNumber..."
$MatchedVoiceRoutes = $VoiceRoutes | Where-Object { $NormalisedNumber -match $_.NumberPattern }
if ($MatchedVoiceRoutes) {
$ChosenPSTNUsage = $MatchedVoiceRoutes[0].PSTNUsage
# Find Voice Routes that match normalised number and first matching PSTN Usage
Write-Host "`rFirst Matching PSTN Usage: '$ChosenPSTNUsage'"
$MatchedVoiceRoutes = $MatchedVoiceRoutes | Where-Object { $_.PSTNUsage -eq $ChosenPSTNUsage }
Write-Host "`rFound $(@($MatchedVoiceRoutes).Count) Voice Route(s) with matching pattern in PSTN Usage '$ChosenPSTNUsage', listing in priority order..." -ForegroundColor Green
$MatchedVoiceRoutes | Select-Object Name, NumberPattern, PSTNUsage, OnlinePstnGatewayList, Priority | Format-Table
Write-Host "Note: Once a Voice Route that matches is found in a PSTN Usage, all other Voice Routes in other PSTN Usages will be ignored." -ForegroundColor Yellow
}
else {
Write-Warning -Message "No Voice Route with matching pattern found, unable to route call using Direct Routing."
}
}
else {
Write-Warning -Message "No Online Voice Routing Policy assgined to $user."
}
}
else {
Write-Warning -Message "$user not found on tenant."
}