-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck-TeamsUserProvisioning.ps1
More file actions
311 lines (189 loc) · 10.2 KB
/
Check-TeamsUserProvisioning.ps1
File metadata and controls
311 lines (189 loc) · 10.2 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<#
.SYNOPSIS
Check-TeamsUserProvisioning.ps1 - Check Provisioning Status of Teams Users
.DESCRIPTION
Author: Lee Ford
This tool allows you to check the assignment and provisioning status of a single user or batch of users from a CSV file.
It will first check the user(s) Azure AD assignment for Teams licenses - this ensures the assigned license in Azure AD has been provisioned (actioned) correctly. Next, it will check the assignment and provisioning of the _actual_ service(s) in Teams - this is where the delay is normally found.
Once all users have been checked a summary of potential licensing issues is provided.
.LINK
Blog: https://www.lee-ford.co.uk
Twitter: http://www.twitter.com/lee_ford
LinkedIn: https://www.linkedin.com/in/lee-ford/
.EXAMPLE
The script can be ran to check a single user by running:
.\Check-TeamsUserProvisioning.ps1 -UPN user@domain.com
To check for a batch of users you can feed in a CSV (the CSV needs the header 'UPN' with user's UPN listed underneath):
.\Check-TeamsUserProvisioning.ps1 -ImportUserCSV .\Users.csv
To include deleted (unassigned) plans:
.\Check-TeamsUserProvisioning.ps1 -UPN user@domain.com -IncludeDeleted
To exports errors to a path:
.\Check-TeamsUserProvisioning.ps1 -ImportUserCSV .\Users.csv -ExportErrorPath c:\temp\errors
#>
Param (
[Parameter(mandatory = $false)][String]$UPN,
[Parameter(mandatory = $false)][String]$ImportUserCSV,
[Parameter(mandatory = $false)][Switch]$IncludeDeleted,
[Parameter(mandatory = $false)][string]$OverrideAdminDomain,
[Parameter(mandatory = $false)][String]$ExportErrorPath
)
$script:AzureADLicenseIssues = @()
$script:TeamsLicenseIssues = @()
function Check-UserLicense {
param (
[Parameter (mandatory = $true)][String]$UPN
)
# Azure AD
try {
Write-Host "`n----------------------------------------------------------------------------------------------
`n $UPN
`n----------------------------------------------------------------------------------------------" -ForegroundColor Yellow
$AADLicenses = (Get-AzureADUser -ObjectId $UPN | Get-AzureADUserLicenseDetail).ServicePlans | Where-Object { $_.ServicePlanName -like "MCO*" -or $_.ServicePlanName -like "Teams*" } | Sort-Object -Property ServicePlanName -ErrorAction Stop
Write-Host "`n`rAzure AD Provisioning Status for $UPN..." -ForegroundColor Blue -BackgroundColor Black
$AADLicenses | Format-Table
$AADLicenses | ForEach-Object {
if ([string]$_.ProvisioningStatus -ne "Success" -and [string]$_.ProvisioningStatus -ne "Deleted") {
# Potential Licensing Issue
$AzureADLicenseIssue = @{ }
$AzureADLicenseIssue.UPN = $UPN
$AzureADLicenseIssue.ProvisioningStatus = $_.ProvisioningStatus
$AzureADLicenseIssue.ServicePlanId = $_.ServicePlanId
$AzureADLicenseIssue.ServicePlanName = $_.ServicePlanName
$script:AzureADLicenseIssues += New-Object PSObject -Property $AzureADLicenseIssue
}
}
# Teams
$user = Get-CSOnlineUser -Identity $UPN | Select-Object AssignedPlan, ProvisionedPlan
$assingedPlans = @()
$user.assignedPlan | ForEach-Object {
$assignedPlan = $_ | Select-String -Pattern 'Plan=(")(.*?)\1'
$assignedPlan = $assignedPlan.Matches.Groups[2]
$assignedPlanId = $_ | Select-String -Pattern 'SubscribedPlanId=(")(.*?)\1'
$assignedPlanId = $assignedPlanId.Matches.Groups[2]
$assignedPlanCapabilityStatus = $_ | Select-String -Pattern 'CapabilityStatus=(")(.*?)\1'
$assignedPlanCapabilityStatus = $assignedPlanCapabilityStatus.Matches.Groups[2]
$assignedPlanAssignedTimestamp = $_ | Select-String -Pattern 'AssignedTimestamp=(")(.*?)\1'
$assignedPlanAssignedTimestamp = $assignedPlanAssignedTimestamp.Matches.Groups[2]
# Check if deleted
if ([string]$assignedPlanCapabilityStatus -ne "Deleted" -or $IncludeDeleted) {
$assingedPlan = @{ }
$assingedPlan.AssignedTimestamp = $assignedPlanAssignedTimestamp
$assingedPlan.AssignedStatus = $assignedPlanCapabilityStatus
$assingedPlan.LicensePlan = $assignedPlan
$assingedPlan.SubscribedPlanId = $assignedPlanId
$user.provisionedPlan | ForEach-Object {
$provisionedPlanId = $_ | Select-String -Pattern 'SubscribedPlanId=(")(.*?)\1'
$provisionedPlanId = $provisionedPlanId.Matches.Groups[2]
if ($provisionedPlanId -like "*$assignedPlanId*") {
$provisionedPlanCapabilityStatus = $_ | Select-String -Pattern 'CapabilityStatus=(")(.*?)\1'
$provisionedPlanCapabilityStatus = $provisionedPlanCapabilityStatus.Matches.Groups[2]
$assingedPlan.ProvisioningStatus = $provisionedPlanCapabilityStatus
}
}
$assingedPlans += New-Object PSObject -Property $assingedPlan
if ([string]$assingedPlan.AssignedStatus -ne "Enabled" -and [string]$assingedPlan.AssignedStatus -ne "Deleted" -and [string]$assingedPlan.ProvisioningStatus -ne "Enabled" -and [string]$assingedPlan.ProvisioningStatus -ne "Deleted") {
# Potential Licensing Issue
$TeamsLicenseIssue = @{ }
$TeamsLicenseIssue.UPN = $UPN
$TeamsLicenseIssue.ProvisioningStatus = $assingedPlan.ProvisioningStatus
$TeamsLicenseIssue.AssignedStatus = $assingedPlan.AssignedStatus
$TeamsLicenseIssue.SubscribedPlanId = $assignedPlanId
$TeamsLicenseIssue.LicensePlan = $assignedPlan
$script:TeamsLicenseIssues += New-Object PSObject -Property $TeamsLicenseIssue
}
}
}
Write-Host "`n`rTeams Assignment and Provisioning Status for $UPN..." -ForegroundColor DarkMagenta -BackgroundColor Black
$assingedPlans | Sort-Object -Property LicensePlan | Format-Table
if ($user.MCOValidationError) {
Write-Host "`r`nValidate Error Found: `r`n$($user.MCOValidationError)" -ForegroundColor Red -BackgroundColor Black
}
}
catch {
Write-Warning "UPN not found in Azure AD!"
}
}
function Check-ModuleInstalled {
param (
[Parameter (mandatory = $true)][String]$module,
[Parameter (mandatory = $true)][String]$moduleName
)
# Do you have module installed?
Write-Host "`nChecking $moduleName installed..."
if (Get-Module -ListAvailable -Name $module) {
Write-Host "$moduleName installed." -ForegroundColor Green
}
else {
Write-Error -Message "$moduleName not installed, please install and try again."
break
}
}
function Check-ExistingPSSession {
param (
[Parameter (mandatory = $true)][string]$ComputerName
)
$OpenSessions = Get-PSSession | Where-Object { $_.ComputerName -like $ComputerName -and $_.State -eq "Opened" }
return $OpenSessions
}
# Start
Write-Host "`n----------------------------------------------------------------------------------------------
`n Check-TeamsUserProvisioning.ps1 - Lee Ford - https://www.lee-ford.co.uk
`n----------------------------------------------------------------------------------------------" -ForegroundColor Yellow
# Check Azure AD and Teams modules installed
Check-ModuleInstalled -module MicrosoftTeams -moduleName "Microsoft Teams module"
Check-ModuleInstalled -module AzureAD -moduleName "AzureAD v2 module"
$Connected = Check-ExistingPSSession -ComputerName "api.interfaces.records.teams.microsoft.com"
if (!$Connected) {
Write-Host "No existing PowerShell Sessions..."
Write-Host "`r`nSign in to Teams using prompt (this may appear behind this terminal)..."
Connect-MicrosoftTeams
# Connect to Azure AD
Write-Host "`r`nSign in to AzureAD using prompt (this may appear behind this terminal)..."
Connect-AzureAD
}
else {
Write-Host "Using existing PowerShell Sessions..."
}
if ($ImportUserCSV) {
# Import CSV
$CSV = Import-CSV $ImportUserCSV
$userCount = $CSV.Count
$CSV | ForEach-Object {
# Progress counter
$counter++
# Progress
Write-Progress -Activity "Checking Users" -Status "Checking User $counter of $userCount" -CurrentOperation $_.UPN -PercentComplete (($counter / $userCount) * 100)
Check-UserLicense -UPN $_.UPN
}
}
elseif ($UPN) {
Check-UserLicense -UPN $UPN
}
else {
Write-Warning "No valid parameters specified!"
}
Write-Host "`n----------------------------------------------------------------------------------------------
`n Licensing Summary
`n----------------------------------------------------------------------------------------------" -ForegroundColor Yellow
if ($script:AzureADLicenseIssues) {
Write-Host "`r`nThe following potential Azure AD licensing issues were found:" -ForegroundColor Red
$script:AzureADLicenseIssues | Format-Table
if ($ExportErrorPath) {
Write-Host "Exporting Azure AD License Errors to $ExportErrorPath/AzureADLicenseErrors.csv"
$script:AzureADLicenseIssues | Export-Csv -Path "$ExportErrorPath/AzureADLicenseErrors.csv" -NoTypeInformation
}
}
else {
Write-Host "`r`nNo Azure AD licensing issues were found." -ForegroundColor Green
}
if ($script:TeamsLicenseIssues) {
Write-Host "`r`nThe following potential Teams licensing issues were found:" -ForegroundColor Red
$script:TeamsLicenseIssues | Format-Table
if ($ExportErrorPath) {
Write-Host "Exporting Teams Licenses Errors to $ExportErrorPath/TeamsLicenseErrors.csv"
$script:TeamsLicenseIssues | Export-Csv -Path "$ExportErrorPath/TeamsLicenseErrors.csv" -NoTypeInformation
}
}
else {
Write-Host "`r`nNo Teams licensing issues were found." -ForegroundColor Green
}