-
Notifications
You must be signed in to change notification settings - Fork 0
/
SkypeTeamsOnlineManagement.psm1
1405 lines (1195 loc) · 59.9 KB
/
SkypeTeamsOnlineManagement.psm1
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Requires -Version 3.0
<#
Written by Jeff Brown
Jeff@JeffBrown.tech
@JeffWBrown
www.jeffbrown.tech
https://github.com/JeffBrownTech/SkypeTeamsOnlineManagement
Any and all technical advice, scripts, and documentation are provided as is with no guarantee.
Always review any code and steps before applying to a production system to understand their full impact.
Version Notes
V1.4 - 5/17/2020 - Improved performance of Connect-SkypeOnline
V1.3 - 3/11/2018 - Update new license names; added Common Area Phone to license-related commands
V1.2 - 11/11/2017 - Added Remove-SkypeOnlineNormalizationRule cmdlet
V1.1 - 10/8/2017 - Add non-exported helper functions for AzureAD and Skype connections; fixed a few errors
V1.0 - 10/2/2017 - Initial Version
#>
# *** Exported Functions ***
function Add-SkypeOnlineUserLicense {
<#
.SYNOPSIS
Adds one or more Skype related licenses to a user account.
.DESCRIPTION
Skype for Business Online services are available through assignment of different types of licenses.
This command allows assigning one or more Skype related Office 365 licenses to a user account to enable
the different services, such as E1/E3/E5, Phone System, Calling Plans, and Audio Conferencing.
.PARAMETER Identity
The sign-in address or User Principal Name of the user account to modify.
.PARAMETER AddSkypeStandalone
Adds a Skype for Business Plan 2 license to the user account.
.PARAMETER AddE1
Adds an E1 license to the user account.
.PARAMETER AddE3
Adds an E3 license to the user account.
.PARAMETER AddE5
Adds an E5 license to the user account.
.PARAMETER AddE5NoAudioConferencing
Adds an E5 without Audio Conferencing license to the user account.
.PARAMETER AddAudioConferencing
Adds a Audio Conferencing add-on license to the user account.
.PARAMETER AddPhoneSystem
Adds a Phone System add-on license to the user account.
.PARAMETER AddDomesticCallingPlan
Adds a Domestic Calling Plan add-on license to the user account.
.PARAMETER AddInternationalCallingPlan
Adds an International Calling Plan add-on license to the user account.
.PARAMETER AddCommunicationsCredit
Adds an Communications Credit add-on license to the user account.
.PARAMETER AddCommonAreaPhone
Adds a Common Area Phone license to the user account.
.EXAMPLE
Add-SkypeOnlineUserLicense -Identity Joe@contoso.com -AddE3 -AddPhoneSystem
Example 1 will add the an E3 and Cloud PBX add-on license to Joe@contoso.com
.EXAMPLE
Add-SkypeOnlineUserLicense -Identity Joe@contoso.com -AddE5 -AddDomesticCallingPlan
Example 2 will add the an E5 and Domestic Calling Plan add-on license to Joe@contoso.com
.EXAMPLE
Add-SkypeOnlineUserLicense -Identity Joe@contoso.com -AddSkypeStandalone
Example 3 will add the a Skype for Business Plan 2 license to Joe@contoso.com
.NOTES
The command will test to see if the license exists in the tenant as well as if the user already
has the licensed assigned. It does not keep track or take into account the number of licenses
available before attempting to assign the license.
#>
[CmdletBinding(DefaultParameterSetName = 'AddDomestic')]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'AddDomestic')]
[Parameter(ParameterSetName = 'AddInternational')]
[Alias("UPN", "UserPrincipalName", "Username")]
[string[]]$Identity,
[Parameter(ParameterSetName = 'AddDomestic')]
[Parameter(ParameterSetName = 'AddInternational')]
[switch]$AddSkypeStandalone,
[Parameter(ParameterSetName = 'AddDomestic')]
[Parameter(ParameterSetName = 'AddInternational')]
[switch]$AddE1,
[Parameter(ParameterSetName = 'AddDomestic')]
[Parameter(ParameterSetName = 'AddInternational')]
[switch]$AddE3,
[Parameter(ParameterSetName = 'AddDomestic')]
[Parameter(ParameterSetName = 'AddInternational')]
[switch]$AddE5,
[Parameter(ParameterSetName = 'AddDomestic')]
[Parameter(ParameterSetName = 'AddInternational')]
[switch]$AddE5NoAudioConferencing,
[Parameter(ParameterSetName = 'AddDomestic')]
[Parameter(ParameterSetName = 'AddInternational')]
[switch]$AddAudioConferencing,
[Parameter(ParameterSetName = 'AddDomestic')]
[Parameter(ParameterSetName = 'AddInternational')]
[switch]$AddPhoneSystem,
[Parameter(ParameterSetName = 'AddDomestic')]
[switch]$AddDomesticCallingPlan,
[Parameter(ParameterSetName = 'AddInternational')]
[switch]$AddInternationalCallingPlan,
[Parameter(ParameterSetName = 'AddDomestic')]
[Parameter(ParameterSetName = 'AddInternational')]
[switch]$AddCommunicationsCredit,
[Parameter(ParameterSetName = 'AddDomestic')]
[Parameter(ParameterSetName = 'AddInternational')]
[switch]$AddCommonAreaPhone
)
BEGIN {
<#
# Verify Azure Active Directory PowerShell Module (AzureAD) is installed on the PC
if ((Get-Module -ListAvailable).Name -notcontains "AzureAD")
{
Write-Warning -Message "Azure Active Directory PowerShell module is not installed. Please install and run command again."
RETURN
}
# Attempt to get tenant Account SKUs
# If error is found, attempt connection to Azure AD using Connect-AzureAD
$tenantSKUs = Get-AzureADSubscribedSku -ErrorAction SilentlyContinue -ErrorVariable getAzureADTenantDetail
if ($getAzureADTenantDetail)
{
Write-Warning -Message "You must connect to Azure AD before continuing"
Connect-AzureAD -Credential (Get-Credential -Message "Enter the sign-in name and password for an O365 Global Admin")
$tenantSKUs = Get-AzureADSubscribedSku -ErrorAction STOP
}
#>
if ((TestAzureADModule) -eq $false) { RETURN }
if ((TestAzureADConnection) -eq $false) {
try {
Connect-AzureAD -ErrorAction STOP | Out-Null
}
catch {
Write-Warning $_
CONTINUE
}
}
try {
$tenantSKUs = Get-AzureADSubscribedSku -ErrorAction STOP
}
catch {
Write-Warning $_
RETURN
}
# Build Skype SKU Variables from Available Licenses in the Tenant
foreach ($tenantSKU in $tenantSKUs) {
switch ($tenantSKU.SkuPartNumber) {
"MCOPSTN1" { $DomesticCallingPlan = $tenantSKU.SkuId; break }
"MCOPSTN2" { $InternationalCallingPlan = $tenantSKU.SkuId; break }
"MCOMEETADV" { $AudioConferencing = $tenantSKU.SkuId; break }
"MCOEV" { $PhoneSystem = $tenantSKU.SkuId; break }
"ENTERPRISEPREMIUM" { $E5WithPhoneSystem = $tenantSKU.SkuId; break }
"ENTERPRISEPREMIUM_NOPSTNCONF" { $E5NoAudioConferencing = $tenantSKU.SkuId; break }
"ENTERPRISEPACK" { $E3 = $tenantSKU.SkuId; break }
"STANDARDPACK" { $E1 = $tenantSKU.SkuId; break }
"MCOSTANDARD" { $SkypeStandalonePlan = $tenantSKU.SkuId; break }
"MCOPSTNC" { $CommunicationsCredit = $tenantSKU.SkuId; break }
"MCOCAP" { $CommonAreaPhone = $tenantSKU.SkuId; break }
} # End of switch statement
} # End of foreach $tenantSKUs
} # End of BEGIN
PROCESS {
foreach ($ID in $Identity) {
try {
Get-AzureADUser -ObjectId $ID -ErrorAction STOP | Out-Null
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "Not a valid user account"
Write-Output $output
continue
}
# Get user's currently assigned licenses
$userCurrentLicenses = (Get-AzureADUserLicenseDetail -ObjectId $ID).SkuId
# Skype Standalone Plan
if ($AddSkypeStandalone -eq $true) {
if ($null -ne $SkypeStandalonePlan) {
if ($userCurrentLicenses -notcontains $SkypeStandalonePlan) {
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $SkypeStandalonePlan -ErrorAction STOP
$license = NewLicenseObject -SkuId $SkypeStandalonePlan
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: Skype Standalone Plan license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign Skype Standalone Plan license: $_"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "INFO: User already assigned Skype Standalone Plan"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No Skype Standalone Plan licenses found in tenant"
}
Write-Output $output
}
# E1
if ($AddE1 -eq $true) {
if ($null -ne $E1) {
if ($userCurrentLicenses -notcontains $E1) {
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $E1 -ErrorAction STOP
$license = NewLicenseObject -SkuId $E1
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: E1 license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign E1 license: $_"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "INFO: User already assigned E1"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No E1 licenses found in tenant"
}
Write-Output $output
}
# E3
if ($AddE3 -eq $true) {
# Verify if E3 licenses exist in tenant
if ($null -ne $E3) {
# Verify if user does not have the license assigned
if ($userCurrentLicenses -notcontains $E3) {
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $E3 -ErrorAction STOP
$license = NewLicenseObject -SkuId $E3
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: E3 license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign E3 license: $_"
}
}
else {
$output = Get-ActionOutputObject -Name $ID -Result "INFO: User already assigned E3"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No E3 licenses found in tenant"
}
Write-Output $output
}
# E5 with Phone System
if ($AddE5 -eq $true) {
if ($null -ne $E5WithPhoneSystem) {
if ($userCurrentLicenses -notcontains $E5WithPhoneSystem) {
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $E5WithPhoneSystem -ErrorAction STOP
$license = NewLicenseObject -SkuId $E5WithPhoneSystem
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: E5 license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign E5 license: $_"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "INFO: User already assigned E5"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No E5 licenses found in tenant"
}
Write-Output $output
}
# E5 No PSTN Conferencing
if ($AddE5NoAudioConferencing -eq $true) {
if ($null -ne $E5NoAudioConferencing) {
if ($userCurrentLicenses -notcontains $E5NoAudioConferencing) {
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $E5NoAudioConferencing -ErrorAction STOP
$license = NewLicenseObject -SkuId $E5NoAudioConferencing
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: E5 without Audio Conferencing license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign E5 without Audio Conferencing license: $_"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "INFO: User already assigned E5 without Audio Conferencing"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No E5 without Audio Conferencing licenses found in tenant"
}
Write-Output $output
}
# Audio Conferencing Add-On
if ($AddAudioConferencing -eq $true) {
# Checking to see if $AudioConferencing exists
if ($null -ne $AudioConferencing) {
if ($userCurrentLicenses -notcontains $AudioConferencing) {
# Adding Audio Conferencing SKU to user account
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $AudioConferencing -ErrorAction STOP
$license = NewLicenseObject -SkuId $AudioConferencing
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: Audio Conferencing add-on license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign Audio Conferencing add-on license: $_"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "INFO: User already assigned Audio Conferencing"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No Audio Conferencing add-on licenses found in tenant"
}
# Output results of AudioConferencing assignment
Write-Output $output
}
# Phone System Add-On
if ($AddPhoneSystem -eq $true) {
if ($null -ne $PhoneSystem) {
if ($userCurrentLicenses -notcontains $PhoneSystem) {
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $PhoneSystem -ErrorAction STOP
$license = NewLicenseObject -SkuId $PhoneSystem
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: Phone System add-on license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign Phone System add-on license: $_"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "INFO: User already assigned Phone System add-on"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No Phone System add-on licenses found in tenant"
}
Write-Output $output
}
# Domestic Calling Plan
if ($AddDomesticCallingPlan -eq $true) {
if ($null -ne $DomesticCallingPlan) {
if ($userCurrentLicenses -notcontains $DomesticCallingPlan) {
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $DomesticCallingPlan -ErrorAction STOP
$license = NewLicenseObject -SkuId $DomesticCallingPlan
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: Domestic Calling Plan license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign Domestic Calling Plan license: $_"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "INFO: User already assigned Domestic Calling Plan"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No Domestic Calling Plan licenses found in tenant"
}
Write-Output $output
}
# Domestic & International Calling Plan
if ($AddInternationalCallingPlan -eq $true) {
if ($null -ne $InternationalCallingPlan) {
if ($userCurrentLicenses -notcontains $InternationalCallingPlan) {
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $InternationalCallingPlan -ErrorAction STOP
$license = NewLicenseObject -SkuId $InternationalCallingPlan
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: International Calling Plan license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign International Calling Plan license: $_"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "INFO: User already assigned International Calling Plan"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No International Calling Plan licenses found in tenant"
}
Write-Output $output
}
# Communications Credit
if ($AddCommunicationsCredit -eq $true) {
if ($null -ne $CommunicationsCredit) {
if ($userCurrentLicenses -notcontains $CommunicationsCredit) {
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $CommunicationsCredit -ErrorAction STOP
$license = NewLicenseObject -SkuId $CommunicationsCredit
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: Communications Credit license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign Communications Credit license: $_"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "INFO: User already assigned Communications Credit License"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No Communications Credit licenses found in tenant"
}
Write-Output $output
}
# Common Area Phone
if ($AddCommonAreaPhone -eq $true) {
if ($null -ne $CommonAreaPhone) {
if ($userCurrentLicenses -notcontains $CommonAreaPhone) {
try {
#Set-MsolUserLicense -UserPrincipalName $ID -AddLicenses $CommonAreaPhone -ErrorAction STOP
$license = NewLicenseObject -SkuId $CommonAreaPhone
Set-AzureADUserLicense -ObjectId $ID -AssignedLicenses $license -ErrorAction STOP
$output = GetActionOutputObject2 -Name $ID -Result "SUCCESS: Common Area Phone license assigned"
}
catch {
$output = GetActionOutputObject2 -Name $ID -Result "ERROR: Unable to assign Common Area Phone license: $_"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "INFO: User already assigned Common Area Phone License"
}
}
else {
$output = GetActionOutputObject2 -Name $ID -Result "WARNING: No Common Area Phone licenses found in tenant"
}
Write-Output $output
}
} # End of foreach ($ID in $Identity)
} # End of PROCESS
} # End of Add-SkypeOnlineUserLicense
function Connect-SkypeOnline {
<#
.SYNOPSIS
Creates a remote PowerShell session out to Skype for Business Online.
.DESCRIPTION
Connecting to a remote PowerShell session to Skype for Business Online requires several components
and steps. This function consolidates those activities by 1) verifying the SkypeOnlineConnector is
installed and imported, 2) prompting for username and password to make and to import the session.
.PARAMETER UserName
The username or sign-in address to use when making the remote PowerShell session connection.
.EXAMPLE
Connect-SkypeOnline
Example 1 will prompt for the username and password of an administrator with permissions to connect to Skype for Business Online.
.EXAMPLE
Connect-SkypeOnline -UserName admin@contoso.com
Example 2 will prefill the authentication prompt with admin@contoso.com and only ask for the password for the account to connect out to Skype for Business Online.
.NOTES
Requires that the Skype Online Connector PowerShell module be installed.
#>
[CmdletBinding()]
param(
[Parameter()]
[string]$UserName
)
if ((TestSkypeOnlineModule) -eq $true) {
if ((TestSkypeOnlineConnection) -eq $false) {
$moduleVersion = (Get-Module -Name SkypeOnlineConnector).Version
if ($moduleVersion.Major -le "6") {
# Version 6 and lower do not support MFA authentication for Skype Module PowerShell; also allows use of older PSCredential objects
try {
$SkypeOnlineSession = New-CsOnlineSession -Credential (Get-Credential $UserName -Message "Enter the sign-in address and password of a Global or Skype for Business Admin") -ErrorAction STOP
Import-Module (Import-PSSession -Session $SkypeOnlineSession -AllowClobber -ErrorAction STOP) -Global
}
catch {
$errorMessage = $_
if ($errorMessage -like "*Making sure that you have used the correct user name and password*") {
Write-Warning -Message "Logon failed. Please try again and make sure that you have used the correct user name and password."
}
elseif ($errorMessage -like "*Please create a new credential object*") {
Write-Warning -Message "Logon failed. This may be due to multi-factor being enabled for the user account and not using the latest Skype for Business Online PowerShell module."
}
else {
Write-Warning -Message $_
}
}
}
else {
# This should be all newer version than 6; does not support PSCredential objects but supports MFA
try {
if ($PSBoundParameters.ContainsKey("UserName")) {
$SkypeOnlineSession = New-CsOnlineSession $UserName -ErrorAction STOP
}
else {
$SkypeOnlineSession = New-CsOnlineSession -ErrorAction STOP
}
Import-Module (Import-PSSession -Session $SkypeOnlineSession -AllowClobber -ErrorAction STOP) -Global
}
catch {
Write-Warning -Message $_
}
} # End of if statement for module version checking
}
else {
Write-Warning -Message "A Skype Online PowerShell Sessions already exists. Please run Disconnect-SkypeOnline before attempting this command again."
} # End checking for existing Skype Online Connection
}
else {
Write-Warning -Message "Skype Online PowerShell Connector module is not installed. Please install and try again."
Write-Warning -Message "The module can be downloaded here: https://www.microsoft.com/en-us/download/details.aspx?id=39366"
} # End of testing module existence
} # End of Connect-SkypeOnline
function Disconnect-SkypeOnline {
<#
.SYNOPSIS
Disconnects any current Skype for Business Online remote PowerShell sessions and removes any imported modules.
.EXAMPLE
Disconnect-SkypeOnline
Example 1 will remove any current Skype for Business Online remote PowerShell sessions and removes any imported modules.
#>
[CmdletBinding()]
param()
[bool]$sessionFound = $false
$PSSesssions = Get-PSSession
foreach ($session in $PSSesssions) {
if ($session.ComputerName -like "*.online.lync.com") {
$sessionFound = $true
Remove-PSSession $session
}
}
Get-Module | Where-Object { $_.Description -like "*.online.lync.com*" } | Remove-Module
if ($sessionFound -eq $false) {
Write-Warning -Message "No remote PowerShell sessions to Skype Online currently exist"
}
} # End of Disconnect-SkypeOnline
function Get-SkypeOnlineConferenceDialInNumbers {
<#
.SYNOPSIS
Gathers the audio conference dial-in numbers information for a Skype for Business Online tenant.
.DESCRIPTION
This command uses the tenant's conferencing dial-in number web page to gather a "user-readable" list of
the regions, numbers, and available languages where dial-in conferencing numbers are available. This web
page can be access at https://dialin.lync.com/DialInOnline/Dialin.aspx?path=<DOMAIN> replacing "<DOMAIN>"
with the tenant's default domain name (i.e. contoso.com).
.PARAMETER Domain
The Skype for Business Online Tenant domain to gather the conference dial-in numbers.
.EXAMPLE
Get-SkypeOnlineConferenceDialInNumbers -Domain contoso.com
Example 1 will gather the conference dial-in numbers for contoso.com based on their conference dial-in number web page.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, HelpMessage = "Enter the domain name to gather the available conference dial-in numbers")]
[string]$Domain
)
try {
$siteContents = Invoke-WebRequest https://webdir1a.online.lync.com/DialinOnline/Dialin.aspx?path=$Domain -ErrorAction STOP
}
catch {
Write-Warning -Message "Unable to access that dial-in page. Please check the domain name and try again. Also try to manually navigate to the page using the URL http://dialin.lync.com/DialInOnline/Dialin.aspx?path=$Domain."
RETURN
}
$tables = $siteContents.ParsedHtml.getElementsByTagName("TABLE")
$table = $tables[0]
$rows = @($table.rows)
$output = [PSCustomObject][ordered]@{
Location = $null
Number = $null
Languages = $null
}
for ($n = 0; $n -lt $rows.Count; $n += 1) {
if ($rows[$n].innerHTML -like "<TH*") {
$output.Location = $rows[$n].innerText
}
else {
$output.Number = $rows[$n].cells[0].innerText
$output.Languages = $rows[$n].cells[1].innerText
Write-Output $output
}
}
} # End of Get-SkypeOnlineConferenceDialInNumbers
function Get-SkypeOnlineUserLicense {
<#
.SYNOPSIS
Gathers licenses assigned to a Skype for Business Online user for Cloud PBX and PSTN Calling Plans.
.DESCRIPTION
This script lists the UPN, Name, currently O365 Plan, Calling Plan, Communication Credit, and Audio Conferencing Add-On License
.PARAMETER Identity
The Identity/UPN/sign-in address for the user entered in the format <name>@<domain>.
Aliases include: "UPN","UserPrincipalName","Username"
.EXAMPLE
.\Get-SkypeOnlineLicense.ps1 -Identity John@domain.com
Example 1 will confirm the license for a single user: John@domain.com
.EXAMPLE
.\Get-SkypeOnlineLicense.ps1 -Identity John@domain.com,Jane@domain.com
Example 2 will confirm the licenses for two users: John@domain.com & Jane@domain.com
.EXAMPLE
Import-Csv User.csv | .\Get-SkypeOnlineLicense.ps1
Example 3 will use a CSV as an input file and confirm the licenses for users listed in the file. The input file must
have a single column heading of "Identity" with properly formatted UPNs.
.NOTES
If using a CSV file for pipeline input, the CSV user data file should contain a column name matching each of this script's parameters. Example:
Identity
John@domain.com
Jane@domain.com
Output can be redirected to a file or grid-view.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Enter the UPN or login name of the user account, typically <user>@<domain>.")]
[Alias("UPN", "UserPrincipalName", "Username")]
[string[]]$Identity
)
BEGIN {
if ((TestAzureADModule) -eq $false) { RETURN }
if ((TestAzureADConnection) -eq $false) {
try {
Connect-AzureAD -ErrorAction STOP
}
catch {
Write-Warning $_
CONTINUE
}
}
} # End of BEGIN
PROCESS {
foreach ($User in $Identity) {
try {
Get-AzureADUser -ObjectId $User -ErrorAction STOP | Out-Null
}
catch {
$output = [PSCustomObject][ordered]@{
User = $User
License = "Invalid User"
CallingPlan = "Invalid User"
CommunicationsCreditLicense = "Invalid User"
AudioConferencingAddOn = "Invalid User"
CommoneAreaPhoneLicense = "Invalid User"
}
Write-Output $output
continue
}
$userInformation = Get-AzureADUser -ObjectId $User
$assignedLicenses = (Get-AzureADUserLicenseDetail -ObjectId $User).SkuPartNumber
[string]$DisplayName = $userInformation.Surname + ", " + $userInformation.GivenName
[string]$O365License = $null
[string]$currentCallingPlan = "Not Assigned"
[bool]$CommunicationsCreditLicense = $false
[bool]$AudioConferencingAddOn = $false
[bool]$CommonAreaPhoneLicense = $false
if ($null -ne $assignedLicenses) {
foreach ($license in $assignedLicenses) {
switch -Wildcard ($license) {
"DESKLESSPACK" { $O365License += "Kiosk Plan, "; break }
"EXCHANGEDESKLESS" { $O365License += "Exchange Kiosk, "; break }
"EXCHANGESTANDARD" { $O365License += "Exchange Standard, "; break }
"EXCHANGEENTERPRISE" { $O365License += "Exchange Premium, "; break }
"MCOSTANDARD" { $O365License += "Skype Plan 2, "; break }
"STANDARDPACK" { $O365License += "E1, "; break }
"ENTERPRISEPACK" { $O365License += "E3, "; break }
"ENTERPRISEPREMIUM" { $O365License += "E5, "; break }
"ENTERPRISEPREMIUM_NOPSTNCONF" { $O365License += "E5 (No Audio Conferencing), "; break }
"MCOCAP" { $CommonAreaPhoneLicense = $true; break }
"MCOPSTN1" { $currentCallingPlan = "Domestic"; break }
"MCOPSTN2" { $currentCallingPlan = "Domestic & International"; break }
"MCOPSTNC" { $CommunicationsCreditLicense = $true; break }
"MCOMEETADV" { $AudioConferencingAddOn = $true; break }
}
}
}
else {
$O365License = "No Licenses Assigned"
}
$output = [PSCustomObject][ordered]@{
User = $User
License = $O365License.TrimEnd(", ") # Removes any trailing ", " at the end of the string
CallingPlan = $currentCallingPlan
CommunicationsCreditLicense = $CommunicationsCreditLicense
AudioConferencingAddOn = $AudioConferencingAddOn
CommoneAreaPhoneLicense = $CommonAreaPhoneLicense
}
Write-Output $output
} # End of foreach ($UserPrincipal in $Identity)
} # End of PROCESS
} # End of Get-SkypeOnlineUserLicense
function Get-SkypeOnlineTenantLicenses {
<#
.SYNOPSIS
Displays the Skype individual plans, add-on & grouped license SKUs for a tenant.
.DESCRIPTION
Skype for Business Online services can be provisioned through several different combinations of individual
plans as well as add-on and grouped license SKUs. This command displays these license SKUs in a more friendly
format with descriptive names, active, consumed, remaining, and expiring licenses.
.EXAMPLE
Get-SkypeOnlineTenantLicenses
Example 1 will display all the Skype related licenses for the tenant.
.NOTES
Requires the Azure Active Directory PowerShell module to be installed and authenticated to the tenant's Azure AD instance.
#>
[CmdletBinding()]
param()
if ((TestAzureADModule) -eq $false) { RETURN }
if ((TestAzureADConnection) -eq $false) {
try {
Connect-AzureAD -ErrorAction STOP | Out-Null
}
catch {
Write-Warning $_
CONTINUE
}
}
try {
$tenantSKUs = Get-AzureADSubscribedSku -ErrorAction STOP
}
catch {
Write-Warning $_
RETURN
}
foreach ($tenantSKU in $tenantSKUs) {
[string]$skuFriendlyName = $null
switch ($tenantSKU.SkuPartNumber) {
"MCOPSTN1" { $skuFriendlyName = "Domestic Calling Plan"; break }
"MCOPSTN2" { $skuFriendlyName = "Domestic and International Calling Plan"; break }
"MCOPSTNC" { $skuFriendlyName = "Communications Credit Add-On"; break }
"MCOMEETADV" { $skuFriendlyName = "Audio Conferencing Add-On"; break }
"MCOEV" { $skuFriendlyName = "Phone System Add-On"; break }
"MCOCAP" { $skuFriendlyName = "Common Area Phone"; break }
"ENTERPRISEPREMIUM" { $skuFriendlyName = "Enterprise E5 with Phone System"; break }
"ENTERPRISEPREMIUM_NOPSTNCONF" { $skuFriendlyName = "Enterprise E5 Without Audio Conferencing"; break }
"ENTERPRISEPACK" { $skuFriendlyName = "Enterprise E3"; break }
"STANDARDPACK" { $skuFriendlyName = "Enterprise E1"; break }
"MCOSTANDARD" { $skuFriendlyName = "Skype for Business Online Standalone Plan 2"; break }
"O365_BUSINESS_PREMIUM" { $skuFriendlyName = "O365 Business Premium"; break }
"PHONESYSTEM_VIRTUALUSER" { $skuFriendlyName = "Phone System - Virtual User"; break }
}
if ($skuFriendlyName.Length -gt 0) {
[PSCustomObject][ordered]@{
License = $skuFriendlyName
Available = $tenantSKU.PrepaidUnits.Enabled
Consumed = $tenantSKU.ConsumedUnits
Remaining = $($tenantSKU.PrepaidUnits.Enabled - $tenantSKU.ConsumedUnits)
Expiring = $tenantSKU.PrepaidUnits.Warning
}
}
} # End of foreach ($tenantSKU in $tenantSKUs}
} # End of Get-SkypeOnlineTenantLicenses
function Remove-SkypeOnlineNormalizationRule {
<#
.SYNOPSIS
Removes a normalization rule from a tenant dial plan.
.DESCRIPTION
This command will display the normalization rules for a tenant dial plan in a list with
index numbers. After choosing one of the rule index numbers, the rule will be removed from
the tenant dial plan. This command requires a remote PowerShell session to Skype for Business Online.
.PARAMETER DialPlan
This is the name of a valid dial plan for the tenant. To view available tenant dial plans,
use the command Get-CsTenantDialPlan.
.EXAMPLE
Remove-SkypeOnlineNormalizationRule -DialPlan US-OK-OKC-DialPlan
Example 1 will display the availble normalization rules to remove from dial plan US-OK-OKC-DialPlan.
.NOTES
The dial plan rules will display in format similar the example below:
RuleIndex Name Pattern Translation
--------- ---- ------- -----------
0 Intl Dialing ^011(\d+)$ +$1
1 Extension Rule ^(\d{5})$ +155512$1
2 Long Distance ^1(\d+)$ +1$1
3 Default ^(\d+)$ +1$1
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "Enter the name of the dial plan to modify the normalization rules.")]
[string]$DialPlan
)
if ((TestSkypeOnlineModule) -eq $true) {
if ((TestSkypeOnlineConnection) -eq $false) {
Write-Warning -Message "You must create a remote PowerShell session to Skype Online before continuing."
Connect-SkypeOnline
}
}
else {
Write-Warning -Message "Skype Online PowerShell Connector module is not installed. Please install and try again."
Write-Warning -Message "The module can be downloaded here: https://www.microsoft.com/en-us/download/details.aspx?id=39366"
}
$dpInfo = Get-CsTenantDialPlan -Identity $DialPlan -ErrorAction SilentlyContinue
if ($null -ne $dpInfo) {
$currentNormRules = $dpInfo.NormalizationRules
[int]$ruleIndex = 0
[int]$ruleCount = $currentNormRules.Count
[array]$ruleArray = @()
[array]$indexArray = @()
if ($ruleCount -ne 0) {
foreach ($normRule in $dpInfo.NormalizationRules) {
$output = [PSCustomObject][ordered]@{
'RuleIndex' = $ruleIndex
'Name' = $normRule.Name
'Pattern' = $normRule.Pattern
'Translation' = $normRule.Translation
}
$ruleArray += $output
$indexArray += $ruleIndex
$ruleIndex++
} # End of foreach ($normRule in $dpInfo.NormalizationRules)
# Displays rules to the screen with RuleIndex added
$ruleArray | Out-Host
do {
$indexToRemove = Read-Host -Prompt "Enter the Rule Index of the normalization rule to remove from the dial plan (leave blank to quit without changes)"
if ($indexToRemove -notin $indexArray -and $indexToRemove.Length -ne 0) {
Write-Warning -Message "That is not a valid Rule Index. Please try again or leave blank to quit."
}
} until ($indexToRemove -in $indexArray -or $indexToRemove.Length -eq 0)
if ($indexToRemove.Length -eq 0) { RETURN }
# If there is more than 1 rule left, remove the rule and set to new normalization rules
# If there is only 1 rule left, we have to set -NormalizationRules to $null
if ($ruleCount -ne 1) {
$newNormRules = $currentNormRules
$newNormRules.Remove($currentNormRules[$indexToRemove])
Set-CsTenantDialPlan -Identity $DialPlan -NormalizationRules $newNormRules
}
else {
Set-CsTenantDialPlan -Identity $DialPlan -NormalizationRules $null
}
}
else {
Write-Warning -Message "$DialPlan does not contain any normalization rules."
}
}
else {
Write-Warning -Message "$DialPlan is not a valid dial plan for the tenant. Please try again."
}
} # End of Remove-SkypeOnlineNormalizationRule
function Set-SkypeOnlineUserPolicy {
<#
.SYNOPSIS
Sets policies on a Skype for Business Online user
.DESCRIPTION
Skype for Business Online offers the assignment of several policies to control client, conferencing,
external access, and mobility options. Typically these are assigned using different commands, but
Set-SkypeOnlineUserPolicy allows settings all these with a single command. One or all policy options can
be used during assignment.
.PARAMETER Identity
This is the sign-in address/User Principal Name of the user to configure.
.PARAMETER ClientPolicy
This is the Client Policy to assign to the user.
.PARAMETER ConferencingPolicy
This is the Conferencing Policy to assign to the user.
.PARAMETER ExternalAccessPolicy
This is the External Access Policy to assign to the user.
.PARAMETER MobilityPolicy
This is the Mobility Policy to assign to the user.
.EXAMPLE
Set-SkypeOnlineUserPolicy -Identity John.Doe@contoso.com -ClientPolicy ClientPolicyNoIMURL
Example 1 will set the user John.Does@contoso.com with a client policy.
.EXAMPLE
Set-SkypeOnlineUserPolicy -Identity John.Doe@contoso.com -ClientPolicy ClientPolicyNoIMURL -ConferencingPolicy BposSAllModalityNoFT
Example 2 will set the user John.Does@contoso.com with a client and conferencing policy.
.EXAMPLE
Set-SkypeOnlineUserPolicy -Identity John.Doe@contoso.com -ClientPolicy ClientPolicyNoIMURL -ConferencingPolicy BposSAllModalityNoFT -ExternalAccessPolicy FederationOnly -MobilityPolicy
Example 3 will set the user John.Does@contoso.com with a client, conferencing, external access, and mobility policy.
#>
[CmdletBinding()]
param(