-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
M365CallFlowVisualizerV2.ps1
6364 lines (3656 loc) · 272 KB
/
M365CallFlowVisualizerV2.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
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
<#
.SYNOPSIS
Reads the configuration from a Microsoft 365 Phone System auto attendant or call queue and visualizes the call flow using mermaid-js.
.DESCRIPTION
Reads the configuration from a Microsoft 365 Phone System auto attendant or call queue by either specifying the voice app name and type, unique identity of the voice app or presents a selection of available auto attendants or call queues if none of the identifiers are supplied.
The call flow is then written into either a mermaid (*.mmd) or a markdown (*.md) file containing the mermaid syntax.
Author: Martin Heusser
Version: 3.1.6
Changelog: Moved to repository at .\Changelog.md
Repository: https://github.com/mozziemozz/M365CallFlowVisualizer
Sponsor Project: https://github.com/sponsors/mozziemozz
Website: https://heusser.pro
.PARAMETER Name
-Identity
Specifies the identity of the first / top-level voice app
Required: false
Type: string
Accepted values: unique identifier of an auto attendant or call queue (not resource account) run Get-CsAutoAttendant or Get-CsCallQueue in order to retrieve an identity.
Default value: none
-SetClipBoard
Specifies if the mermaid code should be copied to the clipboard after the script has finished.
Required: false
Type: boolean
Default value: false
-SaveToFile
Specifies if the mermaid code should be saved into either a mermaid or markdown file.
Required: false
Type: boolean
Default value: true
-ExportHtml
Specifies if, in addition to the Markdown or Mermaid file, also a *.htm file should be exported
Required: false
Type: boolean
Default value: true
-ExportPng
Specifies if, the mermaid or markdown file should be converted and saved as a PNG file. This requires Node.JS and @mermaid-js/mermaid-cli + mermaid packages.
Required: false
Type: boolean
Default value: false
-ExportPDF
Specifies if, the mermaid or markdown file should be converted and saved as a PDF file. This requires Node.JS and @mermaid-js/mermaid-cli + mermaid packages.
Required: false
Type: boolean
Default value: false
-PreviewHtml
Specifies if the exported html file should be opened in default / last active browser (only works on Windows systems)
Required: false
Type: switch
Default value: false
-DocFxMode
This switch adds a subfolder in the relative file path of click actions for exported audio file or TTS greetings. It can only be used with a script from another repository. Do not use this manually.
Required: false
Type: switch
Default value: false
-CacheResults
Specifies if the script should read all auto attendants and call queues in each run. If set to true, the script will read the data from the global variables, if they are not null or empty. If set to false, the script will read the data with each run.
Required: false
Type: boolean
Default value: false
-CustomFilePath
Specifies the file path for the output file. The directory must already exist.
Required: false
Type: string
Accepted values: file paths e.g. "C:\Temp"
Default value: ".\" (current folder)
-ShowNestedCallFlows
Specifies whether or not to also display the call flows of nested call queues or auto attendants. If set to false, only the name of nested voice apps will be rendered. Nested call flows won't be expanded.
Required: false
Type: boolean
Default value: true
-ShowNestedHolidayCallFlows
Specifies whether or not to also display the call flows of nested call queues or auto attendants of holiday call handlings. Call flows will be expanded and linked to the holiday subgraph. To use this parameter, -ShowNestedCallFlows must be true.
Required: false
Type: boolean
Default value: false
-ShowNestedHolidayIVRs
Specifies whether or not to also display nested IVRs on Holiday Call Handlings. They will render in the main diagram and not in the Holiday subgraph.
Required: false
Type: boolean
Default value: false
-ShowUserCallingSettings
Specifies whether or not to also display the user calling settings of a Teams user. If set to false, only the name of a user will be rendered.
Required: false
Type: boolean
Default value: true
-ShowNestedUserCallGroups
Specifies if call groups of users should be expanded and included into the diagram.
Required: false
Type: boolean
Default value: false
-ShowNestedUserDelegates
Specifies if delegates s of users should be expanded and included into the diagram.
Required: false
Type: boolean
Default value: false
-CombineDisconnectCallNodes
Specifies whether or not to only display one mermaid node for all disconnect actions. If this is enabled, diagrams are most likely less readable. This does not apply to "DisconnectCall" actions in holiday call handlings.
Required: false
Type: boolean
Default value: false
-CombineCallConnectedNodes
Specifies whether or not to only display one mermaid node for all call connected noed. If this is enabled, diagrams are most likely less readable.
Required: false
Type: boolean
Default value: false
-ShowCqAgentPhoneNumbers
Specifies whether or not the agent subgraphs of call queues should include a users direct number.
Required: false
Type: switch
Default value: false
-ShowCqAgentOptInStatus
Specifies whether or not the current opt in status of agents should be displayed.
Required: false
Type: switch
Default value: false
-ShowPhoneNumberType
Specifies whether or not the phone number type of phone numbers should be displayed. (CallingPlan, OperatorConnect, DirectRouting)
Required: false
Type: switch
Default value: false
-ShowTTSGreetingText
Specifies whether or not the text of TTS greetings should be included in greeting nodes. Note: this can create wide diagrams. Use parameter -TruncateGreetings to shorten the text.
Required: false
Type: switch
Default value: false
-ShowAudioFileName
Specifies whether or not the filename of audio file greetings should be included in greeting nodes. Note: this can create wide diagrams. Use parameter -TruncateGreetings to shorten the filename
Required: false
Type: switch
Default value: false
-TruncateGreetings
Specifies how many characters of the file name or the greeting text should be included. The default value is 20. This will shorten all greetings and filenames to 20 characters, excluding the file name extension.
Required: false
Type: single
Default value: 20
-ExportAudioFiles
Specifies if the audio files of greetings, announcements and music on hold should be exported to the specified directory. If this is enabled, Markdown and HTML output will have clickable links on the greeting nodes which open an audio file in the browser. For this to work, you must also use the -ShowAudioFileName switch.
Required: false
Type: switch
Default value: false
-ExportTTSGreetings
Specifies if the value of TTS greetings and announcements should be exported to the specified directory. If this is enabled, Markdown and HTML output will have clickable links on the greeting nodes with which open a text file in the browser. For this to work, you must also use the -ShowTTSGreetingText switch.
Required: false
Type: switch
Default value: false
-OverrideVoiceIdToFemale
If set to true, all instances of 'Male' voice Id of auto attendants will be overwritten to 'Female'. It's likely that an auto attendants properties say Male even though the aa is using a female voice. This is a bug from MS.
Required: false
Type: switch
Default value: false
-FindUserLinks
This paramter can only be used by the external function Find-CallQueueAndAutoAttendantUserLinks. When this parameter is true, the script will write every user which is part of a call flow into an external variable.
Required: false
Type: switch
Default value: false
-CheckCallFlowRouting
This paramter will check if any Auto attendant (top-level or nested) is currently open or closed based on holiday and business hours schedule. Output is written to the console. By default, your current system date and time and time zone is used to check in respective Auto Attendant time zone.
Required: false
Type: switch
Default value: false
-CheckCallFlowRoutingSpecificDateTime
This paramter can only be used when -CheckCallFlowRouting is $true. Specify any date and time in the future or past to check if an any Auto attendant (top-level or nested) is open or closed based on holiday and business hours schedule on that specific date. Enter the date as string in your local date time format. Example: "19.11.2023 23:59:59"
Required: false
Type: string
Default value: none
-ObfuscatePhoneNumbers
Specifies if phone numbers in call flows should be obfuscated for sharing / example reasons. This will replace the last 4 digits in numbers with an asterisk (*) character. Warning: This will only obfuscate phone numbers in node descriptions. The complete phone number will still be included in Markdown, Mermaid and HTML output!
Required: false
Type: bool
Default value: false
-ShowSharedVoicemailGroupMembers
Specifies if group members (email) should be shown on a shared voicemail node.
Required: false
Type: bool
Default value: false
-ShowSharedVoicemailGroupSubscribers
Specifies if the info if a group member is also following the group mailbox in their personal inbox should be included in the diagram. Requires -ShowSharedVoicemailGroupMembers to be $true
Required: false
Type: bool
Default value: false
-ShowCqOutboundCallingIds
Specifies if outbound calling Ids of call queues should be shown
Required: false
Type: bool
Default value: false
-ShowCqAuthorizedUsers
Specifies if authorized users of call queues should be shown
Required: false
Type: bool
Default value: false
-ShowAaAuthorizedUsers
Specifies if authorized users of auto attendants should be shown
Required: false
Type: bool
Default value: false
-ShowUserOutboundCallingIds
Specifies if outbound calling Ids of individual call queue agents should be shown. This only works if -ShowCqAgentPhoneNumbers is $true
Required: false
Type: bool
Default value: false
-DocType
Specifies the document type.
Required: false
Type: string
Accepted values: Markdown, Mermaid
Default value: Markdown
-DateFormat
Specifies the format of the holiday dates. EU = "dd.MM.yyyy HH:mm" US = "MM.dd.yyyy HH:mm"
Required: false
Type: string
Accepted values: EU, US
Default value: EU
-Theme
Specifies the mermaid theme in Markdown. Custom will use the default hex color codes below if not specified otherwise. Themes are currently only supported for Markdown output.
Required: false
Type: string
Accepted values: default, dark, neutral, forest, custom
Default value: default
-NodeColor
Specifies a custom color for the node fill
Required: false
Type: string
Accepted values: Hexadecimal color codes starting with # enclosed by ""
Default value: "#505AC9"
-NodeBorderColor
Specifies a custom color for the node border
Required: false
Type: string
Accepted values: Hexadecimal color codes starting with # enclosed by ""
Default value: "#464EB8"
-FontColor
Specifies a custom color for the node border
Required: false
Type: string
Accepted values: Hexadecimal color codes starting with # enclosed by ""
Default value: "#FFFFFF"
-LinkColor
Specifies a custom color for links
Required: false
Type: string
Accepted values: Hexadecimal color codes starting with # enclosed by ""
Default value: "#505AC9"
-LinkTextColor
Specifies a custom color for text on links
Required: false
Type: string
Accepted values: Hexadecimal color codes starting with # enclosed by ""
Default value: "#000000"
-SubgraphColor
Specifies a custom color for subgraph backgrounds
Required: false
Type: string
Accepted values: Hexadecimal color codes starting with # enclosed by ""
Default value: "#7B83EB"
-VoiceAppName
If provided, you won't be provided with a selection of available voice apps. The script will search for a voice app with the specified name. This is the display name of a voice app, not a resource account. If you specify the VoiceAppName, VoiceAppType will become mandatory.
Required: false
Type: string
Accepted values: Voice App Name
Default value: none
-VoiceAppType
This becomes mandatory if VoiceAppName is specified. Because an auto attendant and a call queue could have the same arbitrary name, it is neccessary to also specify the type of the voice app, if no unique identity is specified.
Required: true, if VoiceAppName is specified
Type: string
Accepted values: Auto Attendant, Call Queue
Default value: none
-HardcoreMode
When this switch is enabled, all parameters which will gather and display additional data are enabled. This will overwrite any other parameters you might have set. Use it to easily explore the scripts capabilities.
Required: false
Type: switch
Default value: false
-ConnectWithServicePrincipal
Connect to Teams and Graph using your own Entra ID App Registration
Required: false
Type: switch
Default value: false
-EntraTenantIdFileName
Specifies the name of the file to store/read the tenant ID in an encrypted format at .\.local\SecureCreds. If -ConnectWithServicePrincipal is specified/$true this parameter must be specified as well.
Required: false
Type: string
Default value: "m365-cfv-tenant-id"
-EntraApplicationIdFileName
Specifies the name of the file to store/read the app ID in an encrypted format at .\.local\SecureCreds. If -ConnectWithServicePrincipal is specified/$true this parameter must be specified as well.
Required: false
Type: string
Default value: "m365-cfv-app-id"
-EntraClientSecretFileName
Specifies the name of the file to store/read the client secret in an encrypted format at .\.local\SecureCreds. If -ConnectWithServicePrincipal is specified/$true this parameter must be specified as well.
Required: false
Type: string
Default value: "m365-cfv-client-secret"
.INPUTS
None.
.OUTPUTS
Files:
- *.md
- *.mmd
.EXAMPLE
.\M365CallFlowVisualizerV2.ps1
.LINK
https://github.com/mozziemozz/M365CallFlowVisualizer
#>
# Requires -Modules @{ ModuleName = "MicrosoftTeams"; ModuleVersion = "6.1.0" }, "Microsoft.Graph.Users", "Microsoft.Graph.Groups"
[CmdletBinding(DefaultParametersetName="None")]
param(
[Parameter(Mandatory = $false)][String]$Identity,
[Parameter(Mandatory = $false)][Bool]$SetClipBoard = $false,
[Parameter(Mandatory = $false)][Bool]$SaveToFile = $true,
[Parameter(Mandatory = $false)][Bool]$ExportHtml = $true,
[Parameter(Mandatory = $false)][Bool]$ExportPng = $false,
[Parameter(Mandatory=$false)][Bool]$ExportPDF = $false,
[Parameter(Mandatory = $false)][Switch]$PreviewHtml,
[Parameter(Mandatory = $false)][Switch]$DocFxMode,
[Parameter(Mandatory = $false)][Bool]$CacheResults = $false,
[Parameter(Mandatory = $false)][String]$CustomFilePath = ".\Output\$(Get-Date -Format "yyyy-MM-dd")",
[Parameter(Mandatory = $false)][Bool]$ShowNestedCallFlows = $true,
[Parameter(Mandatory = $false)][Bool]$ShowUserCallingSettings = $true,
[Parameter(Mandatory = $false)][Bool]$ShowNestedUserCallGroups = $false,
[Parameter(Mandatory = $false)][Bool]$ShowNestedUserDelegates = $false,
[Parameter(Mandatory = $false)][Bool]$ShowNestedHolidayCallFlows = $false,
[Parameter(Mandatory = $false)][Bool]$ShowNestedHolidayIVRs = $false,
[Parameter(Mandatory = $false)][Bool]$CombineDisconnectCallNodes = $false,
[Parameter(Mandatory = $false)][Bool]$CombineCallConnectedNodes = $false,
[Parameter(Mandatory = $false)][Switch]$ShowCqAgentPhoneNumbers,
[Parameter(Mandatory = $false)][Switch]$ShowCqAgentOptInStatus,
[Parameter(Mandatory = $false)][Switch]$ShowPhoneNumberType,
[Parameter(Mandatory = $false)][Switch]$ShowTTSGreetingText,
[Parameter(Mandatory = $false)][Switch]$ShowAudioFileName,
[Parameter(Mandatory = $false)][Single]$TruncateGreetings = 20,
[Parameter(Mandatory = $false)][Switch]$ExportAudioFiles,
[Parameter(Mandatory = $false)][Switch]$ExportTTSGreetings,
[Parameter(Mandatory = $false)][Switch]$OverrideVoiceIdToFemale,
[Parameter(Mandatory = $false)][Switch]$FindUserLinks,
[Parameter(Mandatory = $false)][Switch]$CheckCallFlowRouting,
[Parameter(Mandatory = $false)][String]$CheckCallFlowRoutingSpecificDateTime,
[Parameter(Mandatory = $false)][Bool]$ObfuscatePhoneNumbers = $false,
[Parameter(Mandatory = $false)][Bool]$ShowSharedVoicemailGroupMembers = $false,
[Parameter(Mandatory = $false)][Bool]$ShowSharedVoicemailGroupSubscribers = $false,
[Parameter(Mandatory = $false)][Bool]$ShowCqOutboundCallingIds = $false,
[Parameter(Mandatory = $false)][Bool]$ShowUserOutboundCallingIds = $false,
[Parameter(Mandatory = $false)][Bool]$ShowCqAuthorizedUsers = $false,
[Parameter(Mandatory = $false)][Bool]$ShowAaAuthorizedUsers = $false,
[Parameter(Mandatory = $false)][ValidateSet("Markdown","Mermaid")][String]$DocType = "Markdown",
[Parameter(Mandatory = $false)][ValidateSet("EU","US")][String]$DateFormat = "EU",
[Parameter(Mandatory = $false)][ValidateSet("default","forest","dark","neutral","custom")][String]$Theme = "default",
[Parameter(Mandatory = $false)][String]$NodeColor = "#505AC9",
[Parameter(Mandatory = $false)][String]$NodeBorderColor = "#464EB8",
[Parameter(Mandatory = $false)][String]$FontColor = "#FFFFFF",
[Parameter(Mandatory = $false)][String]$LinkColor = "#505AC9",
[Parameter(Mandatory = $false)][String]$LinkTextColor = "#000000",
[Parameter(Mandatory = $false)][String]$SubgraphColor = "#7B83EB",
[Parameter(ParameterSetName="VoiceAppProperties",Mandatory = $false)][String]$VoiceAppName,
[Parameter(ParameterSetName="VoiceAppProperties",Mandatory = $true)][ValidateSet("Auto Attendant","Call Queue")][String]$VoiceAppType,
[Parameter(Mandatory = $false)][Switch]$HardcoreMode,
[Parameter(Mandatory = $false)][Switch]$ConnectWithServicePrincipal,
[Parameter(Mandatory = $false)][String]$EntraTenantIdFileName = "m365-cfv-tenant-id",
[Parameter(Mandatory = $false)][String]$EntraApplicationIdFileName = "m365-cfv-app-id",
[Parameter(Mandatory = $false)][String]$EntraClientSecretFileName = "m365-cfv-client-secret"
)
$ErrorActionPreference = "Continue"
# Load Functions
. .\Functions\Connect-M365CFV.ps1
. .\Functions\Read-BusinessHours.ps1
. .\Functions\Optimize-DisplayName.ps1
. .\Functions\Get-TeamsUserCallFlow.ps1
. .\Functions\Get-MsSystemMessage.ps1
. .\Functions\Get-AccountType.ps1
. .\Functions\New-VoiceAppUserLinkProperties.ps1
. .\Functions\Get-SharedVoicemailGroupMembers.ps1
. .\Functions\Get-IvrTransferMessage.ps1
. .\Functions\Get-AutoAttendantDirectorySearchConfig.ps1
. .\Functions\Get-AllVoiceAppsAndResourceAccounts.ps1
. .\Functions\Get-AllVoiceAppsAndResourceAccountsAppAuth.ps1
. .\Functions\SecureCredsMgmt.ps1
. .\Functions\Connect-MsTeamsServicePrincipal.ps1
# Connect to MicrosoftTeams and Microsoft.Graph
if ($ConnectWithServicePrincipal) {
if ($ShowSharedVoicemailGroupSubscribers -eq $true -or $HardcoreMode -eq $true) {
Write-Warning -Message "Shared voicemail group subscribers are not supported with ConnectWithServicePrincipal. Please disable this switch."
Read-Host -Prompt "Press Enter to exit..."
exit
}
Write-Warning -Message "Connecting to Microsoft Teams and Microsoft Graph using your own Entra ID App Registration is not supported yet because it doesn't support [Get|Set|New|Sync]-CsOnlineApplicationInstance yet. Please don't use this parameter yet. https://learn.microsoft.com/en-us/MicrosoftTeams/teams-powershell-application-authentication#cmdlets-supported"
$checkGetCsOnlineUser = Get-CsOnlineUser -ResultSize 1 -ErrorAction SilentlyContinue
if (!$checkGetCsOnlineUser) {
. Get-MZZTenantIdTxt -FileName $EntraTenantIdFileName
. Get-MZZAppIdTxt -FileName $EntraApplicationIdFileName
. Get-MZZSecureCreds -FileName $EntraClientSecretFileName -NoClipboard > $null
$AppSecret = $passwordDecrypted
. Connect-MsTeamsServicePrincipal -TenantId $TenantId -AppId $AppId -AppSecret $AppSecret
$graphTokenSecureString = $graphToken | ConvertTo-SecureString -AsPlainText -Force
$graphTokenSecureString = $graphToken | ConvertTo-SecureString -AsPlainText -Force
Connect-MgGraph -AccessToken $graphTokenSecureString
}
}
else {
. Connect-M365CFV
}
if ($HardcoreMode -eq $true) {
if ($ConnectWithServicePrincipal -eq $true) {
Write-Warning -Message "Hardcore Mode is not supported with ConnectWithServicePrincipal. Please disable this switch."
Read-Host -Prompt "Press Enter to exit..."
exit
}
Write-Host "Hardcore Mode is enabled. This means that all options will be enabled and included in the output. This may overwrite individual values you set in other parameters!" -ForegroundColor Magenta
$ShowNestedHolidayCallFlows = $true
$ShowNestedHolidayIVRs = $true
$ShowCqAgentPhoneNumbers = $true
$ShowCqAgentOptInStatus = $true
$ShowPhoneNumberType = $true
$ShowTTSGreetingText = $true
$ShowAudioFileName = $true
$TruncateGreetings = 999
$ExportAudioFiles = $true
$ExportTTSGreetings = $true
$ShowSharedVoicemailGroupMembers = $true
$ShowSharedVoicemailGroupSubscribers = $true
$ShowCqOutboundCallingIds = $true
$ShowUserOutboundCallingIds = $true
$ShowCqAuthorizedUsers = $true
$ShowAaAuthorizedUsers = $true
$PreviewHtml = $true
$ExportPng = $true
$OverrideVoiceIdToFemale = $true
$Theme = "dark"
}
Write-Warning -Message "There is currently a bug in MicrosoftTeams PowerShell. Auto attendants are likely to output 'Male' as VoiceId property when queried via PowerShell. `nPlease call your auto attendant's phone number to confirm the voice Id it's using. Use the -OverrideVoiceIdToFemale switch param to change all 'Male' values to 'Female' in diagram output."
if ($SaveToFile -eq $false -and $CustomFilePath -ne ".\Output") {
Write-Warning -Message "Custom file path is specified but SaveToFile is set to false. The call flow won't be saved!"
}
if ($ObfuscatePhoneNumbers -eq $true) {
Write-Warning -Message "Obfuscate phone numbers is True. This will only obfuscate phone numbers in node descriptions. The complete phone number will still be included in Markdown, Mermaid and HTML output!"
}
if (($ExportPng -eq $true) -or ($ExportPDF -eq $true)) {
try {
$ErrorActionPreference = "SilentlyContinue"
$checkNPM = npm list -g
$ErrorActionPreference = "Continue"
}
catch {
Write-Warning -Message "Node.JS is not installed. Please install Node.JS for PNG output.`nwinget install --id=OpenJS.NodeJS -e"
}
try {
$ErrorActionPreference = "SilentlyContinue"
$checkMmdcPackage = mmdc --version
$ErrorActionPreference = "Continue"
}
catch {
Write-Warning -Message "mermaid npm packages is not installed. Please install mermaid npm packages for PNG output. `nnpm install -g @mermaid-js/mermaid-cli"
$ExportPng = $false
$ExportPDF = $false
}
}
# Common arrays and variables
$nestedVoiceApps = @()
$processedVoiceApps = @()
$allMermaidNodes = @()
$allSubgraphs = @()
$audioFileNames = @()
$ttsGreetings = @()
# Get all voice apps and resource accounts from external function
if ($ConnectWithServicePrincipal) {
. Get-AllVoiceAppsAndResourceAccountsAppAuth
}
else {
. Get-AllVoiceAppsAndResourceAccounts
}
$allAutoAttendantIds = $allAutoAttendants.Identity
$allCallQueueIds = $allCallQueues.Identity
$applicationIdAa = "ce933385-9390-45d1-9512-c8d228074e07"
#$applicationIdCq = "11cd3e2e-fccb-42ad-ad00-878b93575e07" # not in use at the moment
switch ($DateFormat) {
EU {
$dateFormatString = "dd.MM.yyyy HH:mm"
}
US {
$dateFormatString = "MM.dd.yyyy HH:mm"
}
Default {
$dateFormatString = "dd.MM.yyyy HH:mm"
}
}
if ($CustomFilePath) {
$FilePath = $CustomFilePath
if (!(Test-Path -Path $FilePath)) {
New-Item -Path $FilePath -ItemType Directory
}
}
else {
$FilePath = "."
}
function Set-Mermaid {
param (
[Parameter(Mandatory = $true)][String]$DocType
)
if ($Theme -eq "custom") {
$MarkdownTheme =@"
%%{init: {'maxTextSize': 99000, 'flowchart' : { 'curve' : 'basis' } } }%%
"@
}
else {
$Theme = $Theme.ToLower()
$MarkdownTheme =@"
%%{init: {'theme': '$($Theme)', 'maxTextSize': 99000, 'flowchart' : { 'curve' : 'basis' } } }%%
"@
}
if ($DocType -eq "Markdown") {
$mdStart =@"
## CallFlowNamePlaceHolder
``````mermaid
$MarkdownTheme
flowchart TB
"@
$mdEnd =@"
``````
"@
$fileExtension = ".md"
}
else {
$mdStart =@"
$MarkdownTheme
flowchart TB
"@
$mdEnd =@"
"@
$fileExtension = ".mmd"
}
$mermaidCode = @()
$mermaidCode += $mdStart
}
function Find-Holidays {
param (
[Parameter(Mandatory = $true)][String]$VoiceAppId
)
$aa = $allAutoAttendants | Where-Object {$_.Identity -eq $VoiceAppId}
if ($aa.CallHandlingAssociations.Type -contains "Holiday") {
$aaHasHolidays = $true
}
else {
$aaHasHolidays = $false
}
if ($aa.VoiceResponseEnabled) {
$aaIsVoiceResponseEnabled = $true
}
else {
$aaIsVoiceResponseEnabled = $false
}
# Check if auto attendant has an operator
$Operator = $aa.Operator
if ($Operator) {
switch ($Operator.Type) {
User {
$OperatorTypeFriendly = "User"
$OperatorUser = (Get-MgUser -UserId $($Operator.Id))
$OperatorName = Optimize-DisplayName -String $OperatorUser.DisplayName
$OperatorIdentity = $OperatorUser.Id
$AddOperatorToNestedVoiceApps = $true
}
ExternalPstn {
$OperatorTypeFriendly = "External Number"
$OperatorName = ($Operator.Id).Replace("tel:","")
$OperatorIdentity = $OperatorName
$AddOperatorToNestedVoiceApps = $false
if ($ObfuscatePhoneNumbers -eq $true) {
$OperatorName = $OperatorName.Remove(($OperatorName.Length -4)) + "****"
}
}
ApplicationEndpoint {
# Check if application endpoint is auto attendant or call queue
$matchingApplicationInstanceCheckAa = $allResourceAccounts | Where-Object {$_.ObjectId -eq $Operator.Id -and $_.ApplicationId -eq $applicationIdAa}
if ($matchingApplicationInstanceCheckAa) {
$MatchingOperatorAa = $allAutoAttendants | Where-Object {$_.ApplicationInstances -contains $Operator.Id}
$OperatorTypeFriendly = "[Auto Attendant"
$OperatorName = "$($MatchingOperatorAa.Name)]"
$OperatorIdentity = $MatchingOperatorAa.Identity
}
else {
$MatchingOperatorCq = $allCallQueues | Where-Object {$_.ApplicationInstances -contains $Operator.Id}
$OperatorTypeFriendly = "[Call Queue"
$OperatorName = "$($MatchingOperatorCq.Name)]"
$OperatorIdentity = $MatchingOperatorCq.Identity
}
$AddOperatorToNestedVoiceApps = $true
}
}
}
else {
$AddOperatorToNestedVoiceApps = $false
}
}
function Find-AfterHours {
param (
[Parameter(Mandatory = $true)][String]$VoiceAppId
)
$aa = $allAutoAttendants | Where-Object {$_.Identity -eq $VoiceAppId}
Write-Host "Reading call flow for: $($aa.Name)" -ForegroundColor Magenta
Write-Host "##################################################" -ForegroundColor Magenta
Write-Host "Voice App Id: $($aa.Identity)" -ForegroundColor Magenta
if ($($aa.Name -ne (Optimize-DisplayName -String $aa.Name))) {
Write-Warning -Message "The Auto Attendant '$($aa.Name)' contains special characters which will be removed in the diagram. New Name: '$(Optimize-DisplayName -String $aa.Name)'"
}
# Create ps object which has no business hours, needed to check if it matches an auto attendants after hours schedule
$aaDefaultScheduleProperties = New-Object -TypeName psobject
#$aaDefaultScheduleProperties | Add-Member -MemberType NoteProperty -Name "ComplementEnabled" -Value $true
$aaDefaultScheduleProperties | Add-Member -MemberType NoteProperty -Name "DisplayMondayHours" -Value "00:00:00-1.00:00:00"
$aaDefaultScheduleProperties | Add-Member -MemberType NoteProperty -Name "DisplayTuesdayHours" -Value "00:00:00-1.00:00:00"
$aaDefaultScheduleProperties | Add-Member -MemberType NoteProperty -Name "DisplayWednesdayHours" -Value "00:00:00-1.00:00:00"
$aaDefaultScheduleProperties | Add-Member -MemberType NoteProperty -Name "DisplayThursdayHours" -Value "00:00:00-1.00:00:00"
$aaDefaultScheduleProperties | Add-Member -MemberType NoteProperty -Name "DisplayFridayHours" -Value "00:00:00-1.00:00:00"
$aaDefaultScheduleProperties | Add-Member -MemberType NoteProperty -Name "DisplaySaturdayHours" -Value "00:00:00-1.00:00:00"
$aaDefaultScheduleProperties | Add-Member -MemberType NoteProperty -Name "DisplaySundayHours" -Value "00:00:00-1.00:00:00"
# Convert to string for comparison
$aaDefaultScheduleProperties = $aaDefaultScheduleProperties | Out-String
# Get the current auto attendants after hours schedule and convert to string
# Check if the auto attendant has business hours by comparing the ps object to the actual config of the current auto attendant
# Additional check for auto attendants which somehow have no schedules at all
if ($aa.Schedules.Type -contains "WeeklyRecurrence") {
$aaAfterHoursScheduleId = ($aa.CallHandlingAssociations | Where-Object {$_.Type -eq "AfterHours"}).ScheduleId
$aaAfterHoursScheduleProperties = ($aa.Schedules | Where-Object {$_.Id -eq $aaAfterHoursScheduleId}).WeeklyRecurrentSchedule
. Read-BusinessHours
if ($aaAfterHoursScheduleProperties.ComplementEnabled -eq $false) {
Write-Warning -Message "Complement is disabled. This can only be set through PowerShell. Any time you change business hours in TAC, coplement will be enabled again."
$mdComplementNo = "Yes"
$mdComplementYes = "No"
}
else {
$mdComplementNo = "No"
$mdComplementYes = "Yes"
}
# Check if the auto attendant has business hours by comparing the ps object to the actual config of the current auto attendant
if ($aaDefaultScheduleProperties -eq ($aaEffectiveScheduleProperties | Out-String)) {
$aaHasAfterHours = $false
}
else {
$aaHasAfterHours = $true
if ($CheckCallFlowRouting -eq $true) {
Write-Host "Checking if Auto Attendant '$($aa.Name)' is currently in business hours or after hours schedule..." -ForegroundColor Magenta
# Local time zone and date time
$localTimeZone = (Get-TimeZone).Id
if ($CheckCallFlowRoutingSpecificDateTime) {
$localDateTime = Get-Date $CheckCallFlowRoutingSpecificDateTime
}
else {
$localDateTime = Get-Date
}
# Time zone configured on Auto Attendant
$toTimeZone = $aa.TimeZoneId
# Convert local time to time zone configured on Auto Attendant
$convertedDateTime = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($localDateTime, $localTimeZone, $toTimeZone)
$currentTimeAtAaTimeZone = $convertedDateTime.ToLongTimeString()
$currentDayOfWeekAtAaTimeZone = $convertedDateTime.DayOfWeek
$dayOfWeekAaScheduleToCheck = $aaAfterHoursScheduleProperties."$($currentDayOfWeekAtAaTimeZone)Hours"
$openTimeRange = @()
foreach ($businessHoursTimeRange in $dayOfWeekAaScheduleToCheck) {
# Check if end time is end of day
if ($businessHoursTimeRange.End.TotalHours -eq 24) {
$businessHoursTimeRangeString = "23:59:59"
}
else {
$businessHoursTimeRangeString = $businessHoursTimeRange.End.ToString()
}
if ($currentTimeAtAaTimeZone -ge ($businessHoursTimeRange.Start).ToString() -and $currentTimeAtAaTimeZone -le $businessHoursTimeRangeString) {
$openTimeRange += $businessHoursTimeRange
}
if ($aaAfterHoursScheduleProperties.ComplementEnabled -eq $true) {
Write-Host "Complement: Enabled" -ForegroundColor Yellow
$complementEnabled = $true
}
else {
Write-Host "Complement: Disabled" -ForegroundColor Yellow
$complementEnabled = $false
}
}
Write-Host "Local Time Zone: $localTimeZone" -ForegroundColor Yellow
Write-Host "Local Date Time: $($localDateTime.ToString('dddd, yyyy-MM-dd HH:mm:ss'))" -ForegroundColor Yellow
Write-Host "Auto Attendant Time Zone: $toTimeZone" -ForegroundColor Yellow
Write-Host "Time in Auto Attendant Time Zone: $($convertedDateTime.ToString('dddd, yyyy-MM-dd HH:mm:ss'))" -ForegroundColor Yellow
$businessHoursTimeRangesStarts = ($dayOfWeekAaScheduleToCheck.Start -join ",").Split(",")
$businessHoursTimeRangesEnds = ($dayOfWeekAaScheduleToCheck.End -join ",").Split(",")
$businessHoursTimeRangesString = ""
$businessHoursTimeRangesIndex = 0
foreach ($time in $businessHoursTimeRangesStarts) {
$businessHoursTimeRangesString += "$($businessHoursTimeRangesStarts[$businessHoursTimeRangesIndex]) - $($businessHoursTimeRangesEnds[$businessHoursTimeRangesIndex]), "
$businessHoursTimeRangesIndex ++
}
$businessHoursTimeRangesString = $businessHoursTimeRangesString.TrimEnd(", ")
$businessHoursTimeRangesString = $businessHoursTimeRangesString.Replace("1.00:00:00","23:59:59")
if ($VoiceAppFileName -eq $aa.Name) {
$topLevelAaInfo = "(initially queried Auto Attendant)"
}
else {
$topLevelAaInfo = "(nested Auto Attendant of initially queried Auto Attendant '$($VoiceAppFileName)')"
}
if ($openTimeRange -and $complementEnabled -eq $true) {
Write-Host "Business Hours for $($currentDayOfWeekAtAaTimeZone) in AA Time Zone: $businessHoursTimeRangesString" -ForegroundColor Yellow
Write-Host "Active Business Hours Time Range for $($currentDayOfWeekAtAaTimeZone): $($openTimeRange.Start) - $(($openTimeRange.End).ToString().Replace("1.00:00:00","23:59:59"))" -ForegroundColor Green
Write-Host "Auto Attendant: '$($aa.Name)' $topLevelAaInfo is currently in business hours schedule (open)" -ForegroundColor Green
Write-Host "Check Call Flow Diagram to see where calls are routed to during business hours..." -ForegroundColor Cyan
}
elseif ($openTimeRange -and $complementEnabled -eq $false) {
Write-Host "After Hours for $($currentDayOfWeekAtAaTimeZone) in AA Time Zone: $businessHoursTimeRangesString" -ForegroundColor Yellow
Write-Host "Active After Hours Time Range for $($currentDayOfWeekAtAaTimeZone): $($openTimeRange.Start) - $(($openTimeRange.End).ToString().Replace("1.00:00:00","23:59:59"))" -ForegroundColor Green
Write-Host "Auto Attendant: '$($aa.Name)' $topLevelAaInfo is currently in afther hours schedule (closed) because Complement is disabled and schedule is not inverted" -ForegroundColor Green
Write-Host "Check Call Flow Diagram to see where calls are routed to during after hours..." -ForegroundColor Cyan
}
elseif (!$openTimeRange -and $complementEnabled -eq $false) {
Write-Host "Business Hours for $($currentDayOfWeekAtAaTimeZone) in AA Time Zone: $businessHoursTimeRangesString" -ForegroundColor Yellow
Write-Host "Auto Attendant: '$($aa.Name)' $topLevelAaInfo is currently in business hours schedule (open) because Complement is disabled and schedule is not inverted" -ForegroundColor Red
Write-Host "Check Call Flow Diagram to see where calls are routed to during business hours..." -ForegroundColor Cyan
}
else {
Write-Host "Business Hours for $($currentDayOfWeekAtAaTimeZone) in AA Time Zone: $businessHoursTimeRangesString" -ForegroundColor Yellow
Write-Host "Auto Attendant: '$($aa.Name)' $topLevelAaInfo is currently in after hours schedule (closed)" -ForegroundColor Red
Write-Host "Check Call Flow Diagram to see where calls are routed to during after hours..." -ForegroundColor Cyan
}