-
Notifications
You must be signed in to change notification settings - Fork 8
/
CAMP.psm1
1797 lines (1533 loc) · 69.7 KB
/
CAMP.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 5.1
<#
.SYNOPSIS
CAMP - Configuration Analyzer for Microsoft Purview (CAMP)
.DESCRIPTION
.NOTES
Neha Pandey
Senior Software Engineer - Microsoft
Kritika Mishra
Software Engineer - Microsoft
Output report uses open source components for HTML formatting
- bootstrap - MIT License - https://getbootstrap.com/docs/4.0/about/license/
- fontawesome - CC BY 4.0 License - https://fontawesome.com/license/free
############################################################################
This sample script is not supported under any Microsoft standard support program or service.
This sample script is provided AS IS without warranty of any kind.
Microsoft further disclaims all implied warranties including, without limitation, any implied
warranties of merchantability or of fitness for a particular purpose. The entire risk arising
out of the use or performance of the sample script and documentation remains with you. In no
event shall Microsoft, its authors, or anyone else involved in the creation, production, or
delivery of the scripts be liable for any damages whatsoever (including, without limitation,
damages for loss of business profits, business interruption, loss of business information,
or other pecuniary loss) arising out of the use of or inability to use the sample script or
documentation, even if Microsoft has been advised of the possibility of such damages.
############################################################################
.LINK
about_functions_advanced
#>
[bool] $global:ErrorOccurred = $false
# TelemetryEnabled
[bool] $global:TelemetryEnabled = $false
# Connection Established
[bool] $global:ConnectionEstablished = $false
[string] $global:EnvironmentName = ""
[string] $global:UserName = ""
function Get-CAMPDirectory {
<#
Gets or creates the CAMP directory in AppData
#>
If ($IsWindows) {
$Directory = "$($env:LOCALAPPDATA)\Microsoft\CAMP"
}
elseif ($IsLinux -or $IsMac) {
$Directory = "$($env:HOME)/CAMP"
}
else {
$Directory = "$($env:LOCALAPPDATA)\Microsoft\CAMP"
}
If (Test-Path $Directory) {
Return $Directory
}
else {
mkdir $Directory | out-null
Return $Directory
}
}
Function Invoke-CAMPConnections {
Param
(
[String]$ExchangeEnvironmentName,
[String]$LogFile
)
try {
try {
$ExchangeVersion = (Get-InstalledModule -name "ExchangeOnlineManagement" -ErrorAction:SilentlyContinue | Sort-Object Version -Desc)[0].Version
}
catch {
$ExchangeVersion = "Error"
write-host "$(Get-Date) Exchange Online Management module is not installed. Installing.."
Write-Verbose "Installing ExchangeOnlineManagement"
Install-Module -Name "ExchangeOnlineManagement" -force
}
if ($ExchangeVersion -eq "Error") {
$ExchangeVersion = (Get-InstalledModule -name "ExchangeOnlineManagement" -ErrorAction:SilentlyContinue | Sort-Object Version -Desc)[0].Version
}
if ("$ExchangeVersion" -lt "2.0.3") {
write-host "$(Get-Date) Your Exchange Online Management module is not updated. Updating.."
Update-Module -Name "ExchangeOnlineManagement" -RequiredVersion 2.0.3
}
$global:ConnectionEstablished = $true
$userName = Read-Host -Prompt 'Input the user name' -ErrorAction:SilentlyContinue
$global:UserName = $userName
$InfoMessage = "Connecting to Exchange Online (Modern Module).."
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
Connect-ExchangeOnline -Prefix EXOP -UserPrincipalName $userName -ExchangeEnvironmentName $ExchangeEnvironmentName -ShowBanner:$false -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue
}
catch {
Write-Host "Error:$(Get-Date) There was an issue in connecting to Exchange Online. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
try {
switch ($ExchangeEnvironmentName) {
#O365China { }
#O365GermanyCloud { $ConnectionUri = 'https://ps.compliance.protection.outlook.de/' }
O365USGovDoD { $ConnectionUri = 'https://l5.ps.compliance.protection.office365.us/powershell-liveid/' }
O365USGovGCCHigh { $ConnectionUri = 'https://ps.compliance.protection.office365.us/powershell-liveid/' }
Default { $ConnectionUri = '' }
}
$InfoMessage = "Connecting to Security & Compliance Center"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
if ($ConnectionUri -eq '') {
Connect-IPPSSession -UserPrincipalName $userName -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue
}
else {
Connect-IPPSSession -UserPrincipalName $userName -ConnectionUri $ConnectionUri -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue
}
try { $statusCode = wget http://aka.ms/mcca-execution -Method head | % { $_.StatusCode } }catch {}
}
catch {
Write-Host "Error:$(Get-Date) There was an issue in connecting to Security & Compliance Center. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
throw 'There was an issue in connecting to Security & Compliance Center. Please try running the tool again after some time.'
}
}
enum CheckType {
ObjectPropertyValue
PropertyValue
}
[Flags()]
enum CAMPService {
DLP = 1
OATP = 2
}
enum CAMPConfigLevel {
None = 0
Recommendation = 4
Ok = 5
Informational = 10
TooStrict = 15
}
enum CAMPResult {
Pass = 1
Recommendation = 2
Fail = 3
}
Class CAMPCheckConfig {
CAMPCheckConfig() {
# Constructor
$this.Results += New-Object -TypeName CAMPCheckConfigResult -Property @{
Level = [CAMPConfigLevel]::Recommendation
}
$this.Results += New-Object -TypeName CAMPCheckConfigResult -Property @{
Level = [CAMPConfigLevel]::Ok
}
$this.Results += New-Object -TypeName CAMPCheckConfigResult -Property @{
Level = [CAMPConfigLevel]::Informational
}
$this.Results += New-Object -TypeName CAMPCheckConfigResult -Property @{
Level = [CAMPConfigLevel]::TooStrict
}
}
# Set the result for this mode
SetResult([CAMPConfigLevel]$Level, $Result) {
($this.Results | Where-Object { $_.Level -eq $Level }).Value = $Result
# The level of this configuration should be its strongest result (e.g if its currently Ok and we have a Informational pass, we should make the level Informational)
if ($Result -eq "Pass" -and ($this.Level -lt $Level -or $this.Level -eq [CAMPConfigLevel]::None)) {
$this.Level = $Level
}
elseif ($Result -eq "Fail" -and ($Level -eq [CAMPConfigLevel]::Recommendation -and $this.Level -eq [CAMPConfigLevel]::None)) {
$this.Level = $Level
}
}
$Check
$Object
$ConfigItem
$ConfigData
$InfoText
[string]$RemediationAction = ""
[array]$Results
[CAMPConfigLevel]$Level
}
Class CAMPCheckConfigResult {
[CAMPConfigLevel]$Level = [CAMPConfigLevel]::Ok
$Value
}
Class CAMPRemediationInfo {
[bool]$RemediationAvailable = $false
[string]$RemediationText = ""
}
Class CAMPCheck {
<#
Check definition
The checks defined below allow contextual information to be added in to the report HTML document.
- Control : A unique identifier that can be used to index the results back to the check
- Area : The area that this check should appear within the report
- PassText : The text that should appear in the report when this 'control' passes
- FailRecommendation : The text that appears as a title when the 'control' fails. Short, descriptive. E.g "Do this"
- Importance : Why this is important
- ExpandResults : If we should create a table in the callout which points out which items fail and where
- ObjectType : When ExpandResults is set to, For Object, Property Value checks - what is the name of the Object, e.g a Spam Policy
- ItemName : When ExpandResults is set to, what does the check return as ConfigItem, for instance, is it a Transport Rule?
- DataType : When ExpandResults is set to, what type of data is returned in ConfigData, for instance, is it a Domain?
#>
[Array] $Config = @()
[string] $Control
[string] $ParentArea
[String] $Area
[String] $Name
[String] $PassText
[String] $FailRecommendation
[Boolean] $ExpandResults = $false
[String] $ObjectType
[String] $ItemName
[String] $DataType
[String] $Importance
[CAMPService]$Services = [CAMPService]::DLP
[CheckType] $CheckType = [CheckType]::PropertyValue
[CAMPRemediationInfo] $CAMPRemediationInfo
[string] $LogFile
[string] $ExchangeEnvironmentNameForCheck = $global:EnvironmentName
$Links
$CAMPParams
[CAMPResult] $Result = [CAMPResult]::Pass
[int] $FailCount = 0
[int] $PassCount = 0
[int] $InfoCount = 0
[Boolean] $Completed = $false
# Overridden by check
GetResults($Config) { }
AddConfig([CAMPCheckConfig]$Config) {
$this.Config += $Config
$this.FailCount = @($this.Config | Where-Object { $_.Level -eq [CAMPConfigLevel]::None }).Count
$this.PassCount = @($this.Config | Where-Object { $_.Level -eq [CAMPConfigLevel]::Ok -or $_.Level -eq [CAMPConfigLevel]::Informational }).Count
$this.InfoCount = @($this.Config | Where-Object { $_.Level -eq [CAMPConfigLevel]::Recommendation }).Count
If ($this.FailCount -eq 0 -and $this.InfoCount -eq 0) {
$this.Result = [CAMPResult]::Pass
}
elseif ($this.FailCount -eq 0 -and $this.InfoCount -gt 0) {
$this.Result = [CAMPResult]::Recommendation
}
else {
$this.Result = [CAMPResult]::Fail
}
}
# Run
Run($Config) {
Write-Host "$(Get-Date) Analysis - $($this.Area) - $($this.Name)"
$this.GetResults($Config)
# If there is no results to expand, turn off ExpandResults
if ($this.Config.Count -eq 0) {
$this.ExpandResults = $false
}
}
}
Class CAMPOutput {
[String] $Name
[Boolean] $Completed = $False
$VersionCheck
$DefaultOutputDirectory
$Result
# Function overridden
RunOutput($Checks, $Collection) {
}
Run($Checks, $Collection) {
$this.RunOutput($Checks, $Collection)
$this.Completed = $True
}
}
Class RemediationAction {
[String] $Name
[Boolean] $Completed = $False
$VersionCheck
$DefaultOutputDirectory
$Result
# Function overridden
RunOutput($Checks, $Collection) {
}
Run($Checks, $Collection) {
$this.RunOutput($Checks, $Collection)
$this.Completed = $True
}
}
Function Get-CAMPCheckDefs {
Param
(
[string]$LogFile,
$CAMPParams,
$Collection
)
$Checks = @()
# Load individual check definitions
$CheckFiles = Get-ChildItem "$PSScriptRoot\Checks"
# DLP check file full name
$DLPCheckFileName = $null
#Setting DLP check file name
ForEach ($CheckFile in $CheckFiles) {
if (($CheckFile.BaseName -match '^check-(.*)$') -and ($matches[1] -like "DLP")) {
$DLPCheckFileName = $CheckFile.FullName
}
}
#Creating DLP check objects for each improvement actions
#read xml doc
if ($($Collection["GetRequiredSolution"]) -icontains "DLP") {
[xml]$CheckData = Get-Content "$PSScriptRoot\DLPImprovementActions\ActionsInformation.xml"
if ($null -eq $CheckData -or $CheckData -eq "") {
Write-Host "$(Get-Date) ActionsInformation.xml file does not exist/is corrupt in $PSScriptRoot\DLPImprovementActions\ActionsInformation.xml." -ForegroundColor Orange
}
if ($null -ne $DLPCheckFileName -or $DLPCheckFileName -ne "") {
Write-Verbose "Importing DLP"
. $DLPCheckFileName
foreach ($Item in $CheckData.ImprovementActions.ActionItem) {
#List of SIT
$ListOfSIT = @()
$AllSITS = $Item.SITs.SIT
#Adding custom SITS
<# if($($Collection["GetDLPCustomSIT"]) -ne "Error")
{
$CustomSIT = $($Collection["GetDLPCustomSIT"]).Name
foreach ($sit in $CustomSIT) {
$ListOfSIT += $sit
}
}
#>
if ($($Collection["GetOrganisationRegion"]) -eq "Error") {
foreach ($sit in $AllSITS) {
$ListOfSIT += $sit.InnerText
}
}
else {
foreach ($sit in $AllSITS) {
if ($($Collection["GetOrganisationRegion"]) -contains $($sit.Geo)) {
$ListOfSIT += $sit.InnerText
}
}
}
#Hash table of links
$LinksInfo = @{}
if ($global:EnvironmentName -ieq "O365USGovGCCHigh") {
$AllLinks = $Item.GCCLinks.Link
}
elseif ($global:EnvironmentName -ieq "O365USGovDoD") {
$AllLinks = $Item.DODLinks.Link
}
else {
$AllLinks = $Item.Links.Link
}
foreach ($url in $AllLinks) {
$LinksInfo[$url.LinkText] = $url.ActualURL
}
$InfoParams = @{}
$InfoParams["Control"] = $Item.CheckName
$InfoParams["ParentArea"] = $Item.ParentArea
$InfoParams["Area"] = $Item.Area
$InfoParams["Name"] = $Item.Name
$InfoParams["RemediationPolicyName"] = $Item.RemediationPolicyName
$InfoParams["PassText"] = $Item.PassText
$InfoParams["FailRecommendation"] = $Item.FailRecommendation
$InfoParams["Importance"] = $Item.Importance
$InfoParams["SIT"] = $ListOfSIT
$InfoParams["Links"] = $LinksInfo
$Check = New-Object -TypeName "DLP" -ArgumentList $InfoParams
# Set the CAMPParams
$Check.CAMPParams = $CAMPParams
$Check.LogFile = $LogFile
$Checks += $Check
}
}
}
# Creating Non-DLP check objects for each improvement actions
ForEach ($CheckFile in $CheckFiles) {
if ($CheckFile.BaseName -match '^check-(.*)$' -and ($matches[1] -notlike "DLP")) {
$solutioname = $matches[1]
$length = $solutioname.length
$solutioname = $solutioname.substring(0, $length - 3)
if (($null -ne $($Collection["GetRequiredSolution"])) -and ($($Collection["GetRequiredSolution"]) -icontains "$solutioname")) {
Write-Verbose "Importing $($matches[1])"
. $CheckFile.FullName
$Check = New-Object -TypeName $matches[1]
# Set the CAMPParams
$Check.CAMPParams = $CAMPParams
$Check.LogFile = $LogFile
$Checks += $Check
}
}
}
ForEach ($CheckFile in $CheckFiles) {
if ($CheckFile.BaseName -match '^check-(.*)$' -and ($matches[1] -like "ComplianceManager")) {
#write-host "abc"
Write-Verbose "Importing $($matches[1])"
. $CheckFile.FullName
$Check = New-Object -TypeName $matches[1]
# Set the CAMPParams
$Check.CAMPParams = $CAMPParams
$Check.LogFile = $LogFile
$Checks += $Check
}
}
$Checks = $Checks | Sort-Object -Property @{ expression = 'ParentArea' ; descending = $true }, @{expression = 'Area' ; descending = $false }
Return $Checks
}
Function Get-CAMPRemediationAction {
Param
(
$VersionCheck
)
$RemediationActions = @()
# Load individual check definitions
$RemediationActionOutputFiles = Get-ChildItem "$PSScriptRoot\Remediation"
ForEach ($RemediationActionOutputFile in $RemediationActionOutputFiles) {
if ($RemediationActionOutputFile.BaseName -match '^remediation(.*)$') {
Write-Verbose "Importing $($matches[1])"
. $RemediationActionOutputFile.FullName
$RemediationAction = New-Object -TypeName $matches[1]
# For default output directory
$RemediationAction.DefaultOutputDirectory = Get-CAMPDirectory
# Provide versioncheck
$RemediationAction.VersionCheck = $VersionCheck
$RemediationActions += $RemediationAction
}
}
Return $RemediationActions
}
Function Get-CAMPOutputs {
Param
(
$VersionCheck,
$Modules,
$Options
)
$Outputs = @()
# Load individual check definitions
$OutputFiles = Get-ChildItem "$PSScriptRoot\Outputs"
ForEach ($OutputFile in $OutputFiles) {
if ($OutputFile.BaseName -match '^output-(.*)$') {
# Determine if this type should be loaded
If ($Modules -contains $matches[1]) {
Write-Verbose "Importing $($matches[1])"
. $OutputFile.FullName
$Output = New-Object -TypeName $matches[1]
# Load any of the options in to the module
If ($Options) {
If ($Options[$matches[1]].Keys) {
ForEach ($Opt in $Options[$matches[1]].Keys) {
# Ensure this property exists before we try set it and get a null ref error
$ModProperties = $($Output | Get-Member | Where-Object { $_.MemberType -eq "Property" }).Name
If ($ModProperties -contains $Opt) {
$Output.$Opt = $Options[$matches[1]][$Opt]
}
else {
Throw("There is no option $($Opt) on output module $($matches[1])")
}
}
}
}
# For default output directory
$Output.DefaultOutputDirectory = Get-CAMPDirectory
# Provide versioncheck
$Output.VersionCheck = $VersionCheck
$Outputs += $Output
}
}
}
Return $Outputs
}
# Get DLP settings
Function Get-DataLossPreventionSettings {
Param(
$Collection,
[string]$LogFile
)
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["GetDlpComplianceRule"] = Get-DlpComplianceRule -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
$Collection["GetDLPCustomSIT"] = Get-DlpSensitiveInformationType -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage | Where-Object { $_.Publisher -ne "Microsoft Corporation" }
$Collection["GetDlpCompliancePolicy"] = Get-DlpCompliancePolicy -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetDlpComplianceRule"] = "Error"
$Collection["GetDLPCustomSIT"] = "Error"
$Collection["GetDlpCompliancePolicy"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching Data Loss Prevention information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
Return $Collection
}
# Get Information Protection settings
Function Get-InformationProtectionSettings {
Param(
$Collection,
[string]$LogFile
)
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["GetLabel"] = Get-Label -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
try {
$Collection["GetLabelPolicy"] = Get-LabelPolicy -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
}
catch {
$Collection["GetLabelPolicy"] = "Error"
}
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetLabel"] = "Error"
$Collection["GetLabelPolicy"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching Information Protection information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["GetAutoSensitivityLabelPolicy"] = Get-AutoSensitivityLabelPolicy -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetAutoSensitivityLabelPolicy"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching AutoSensitivity Label Policy information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["GetIRMConfiguration"] = Get-EXOPIRMConfiguration -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetIRMConfiguration"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching IRM Configuration information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
Return $Collection
}
# Get Communication Compliance settings
Function Get-CommunicationComplianceSettings {
Param(
$Collection,
[string]$LogFile
)
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["GetSupervisoryReviewPolicyV2"] = Get-SupervisoryReviewPolicyV2 -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
try {
$Collection["GetSupervisoryReviewOverallProgressReport"] = Get-SupervisoryReviewOverallProgressReport -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
}
catch {
$Collection["GetSupervisoryReviewOverallProgressReport"] = "Error"
}
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetSupervisoryReviewPolicyV2"] = "Error"
$Collection["GetSupervisoryReviewOverallProgressReport"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching Communication Compliance information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
Return $Collection
}
# Get Information Governance settings
Function Get-InformationGovernanceSettings {
Param(
$Collection,
[string]$LogFile
)
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["GetRetentionCompliancePolicy"] = Get-RetentionCompliancePolicy -DistributionDetail -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
$Collection["GetRetentionComplianceRule"] = Get-RetentionComplianceRule -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
$Collection["GetComplianceTag"] = Get-ComplianceTag -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetRetentionCompliancePolicy"] = "Error"
$Collection["GetRetentionComplianceRule"] = "Error"
$Collection["GetComplianceTag"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching Retention Compliance information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
Return $Collection
}
# Get Audit settings
Function Get-AuditSettings {
Param(
$Collection,
[string]$LogFile
)
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["GetAdminAuditLogConfig"] = Get-EXOPAdminAuditLogConfig -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetAdminAuditLogConfig"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching Audit Configuration information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
Return $Collection
}
#get eDiscovery
Function Get-eDiscoverySettings {
Param(
$Collection,
[string]$LogFile
)
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["GetComplianceCase"] = Get-ComplianceCase -CaseType AdvancedEdiscovery -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
$Collection["GetComplianceCaseCore"] = Get-ComplianceCase -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetComplianceCase"] = "Error"
$Collection["GetComplianceCaseCore"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching Audit Configuration information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
Return $Collection
}
#Get Insider Risk Management Settings
Function Get-InsiderRiskManagementSettings {
Param(
$Collection,
[string]$LogFile
)
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["GetInsiderRiskPolicy"] = Get-InsiderRiskPolicy -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetInsiderRiskPolicy"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching Insider Risk Management information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
Return $Collection
}
# Get Accepted Domains
Function Get-AcceptedDomains {
Param(
$Collection,
[string]$LogFile
)
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["AcceptedDomains"] = Get-EXOPAcceptedDomain -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["AcceptedDomains"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching tenant name information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
Return $Collection
}
#Get Alert Policies
Function Get-AlertPolicies {
Param(
$Collection,
[string]$LogFile
)
try {
[System.Collections.ArrayList]$WarnMessage = @()
$Collection["GetProtectionAlert"] = Get-ProtectionAlert | Where-Object { $_.Severity -eq "High" } -ErrorAction:SilentlyContinue -WarningVariable +WarnMessage
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetProtectionAlert"] = "Error"
Write-Host "Error:$(Get-Date) There was an issue in fetching Alert Policies Configuration information. Please try running the tool again after some time." -ForegroundColor:Red
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
Return $Collection
}
#Get Organisation Region
Function Get-OrganisationRegion {
Param(
$Collection,
[string]$LogFile,
[System.Collections.ArrayList] $GeoList
)
try {
[System.Collections.ArrayList]$WarnMessage = @()
[System.Collections.ArrayList] $RegionNamesList = @()
$Collection["GetOrganisationConfig"] = Get-EXOPOrganizationConfig -ErrorAction:SilentlyContinue
if ($($GeoList.Count) -gt 0) {
$Collection["GetOrganisationRegion"] = $GeoList
$Collection["GetOrganisationRegion"].add("INTL") | out-null
}
else {
$RegionsList = $Collection["GetOrganisationConfig"].AllowedMailboxRegions
foreach ($region in $RegionsList) {
$RegionName = $($region.Split("="))[0]
$RegionName = $RegionName.ToUpper()
$RegionNamesList.add($RegionName) | Out-Null
}
$Collection["GetOrganisationRegion"] = $RegionNamesList
$Collection["GetOrganisationRegion"].add("INTL") | out-null
}
Write-Log -IsWarn -WarnMessage $WarnMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
}
catch {
$Collection["GetOrganisationConfig"] = "Error"
if ($($GeoList.Count) -gt 0) {
$Collection["GetOrganisationRegion"] = $GeoList
$Collection["GetOrganisationRegion"].add("INTL") | out-null
}
else {
$Collection["GetOrganisationRegion"] = "Error"
Write-Host "Warning:$(Get-Date) There was an issue in fetching your tenant's geolocation. The generated report will have recommendations for all geos across the globe." -ForegroundColor:Yellow
}
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
Return $Collection
}
#Get Solution Config
Function Get-PersonalizedSolution {
Param(
$Collection,
[string]$LogFile,
[System.Collections.ArrayList] $SolutionList
)
[System.Collections.ArrayList] $SolutionsList = @()
if ($($SolutionList.Count) -gt 0) {
$Collection["GetRequiredSolution"] = $SolutionList
$Collection["GetRequiredSolution"].add("INTL") | out-null
}
else {
$SolutionTable = Get-SolutionTable
[int] $count = 1
while ($count -le 8) {
$SolutionList.add($($($SolutionTable[$count]).Code)) | out-null
$count = $count + 1
}
$Collection["GetRequiredSolution"] = $SolutionsList
$Collection["GetRequiredSolution"].add("INTL") | out-null
}
Return $Collection
}
# Get user configurations
Function Get-CAMPCollection {
Param
(
[String]$LogFile,
[System.Collections.ArrayList] $GeoList,
[System.Collections.ArrayList] $SolutionList
)
$Collection = @{}
[CAMPService]$Collection["Services"] = [CAMPService]::DLP
try {
Write-EXOPAdminAuditLog -Comment "Configuration Analyzer for Microsoft Purview Started at- $(Get-Date)"
}
catch {
$ErrorMessage = $_.ToString()
$StackTraceInfo = $_.ScriptStackTrace
Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
}
if ($SolutionList -icontains "DLP") {
$InfoMessage = "Getting DLP Settings"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-DataLossPreventionSettings -Collection $Collection -LogFile $LogFile
}
if ($SolutionList -icontains "IP") {
$InfoMessage = "Getting Information Protection Settings"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-InformationProtectionSettings -Collection $Collection -LogFile $LogFile
}
if ($SolutionList -icontains "CC") {
$InfoMessage = "Getting Communication Compliance Settings"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-CommunicationComplianceSettings -Collection $Collection -LogFile $LogFile
}
if (($SolutionList -icontains "IG") -or ($SolutionList -icontains "RM")) {
$InfoMessage = "Getting Information Governance Settings"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-InformationGovernanceSettings -Collection $Collection -LogFile $LogFile
}
if ($SolutionList -icontains "Audit" ) {
$InfoMessage = "Getting Audit Settings"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-AuditSettings -Collection $Collection -LogFile $LogFile
}
if ($SolutionList -icontains "eDiscovery") {
$InfoMessage = "Getting eDiscovery Settings"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-eDiscoverySettings -Collection $Collection -LogFile $LogFile
}
if ($SolutionList -icontains "IRM") {
$InfoMessage = "Getting Insider Risk Management Settings"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-InsiderRiskManagementSettings -Collection $Collection -LogFile $LogFile
}
$InfoMessage = "Getting Accepted Domains"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-AcceptedDomains -Collection $Collection -LogFile $LogFile
$InfoMessage = "Getting Alert Policies Settings"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-AlertPolicies -Collection $Collection -LogFile $LogFile
$InfoMessage = "Getting Organization's region information"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-OrganisationRegion -GeoList $GeoList -Collection $Collection -LogFile $LogFile
$InfoMessage = "Getting Organization's solution preference information"
Write-Host "$(Get-Date) $InfoMessage"
Write-Log -IsInfo -InfoMessage $InfoMessage -LogFile $LogFile -ErrorAction:SilentlyContinue
$Collection = Get-PersonalizedSolution -SolutionList $SolutionList -Collection $Collection -LogFile $LogFile
Return $Collection
}
Function Get-CAMPReport {
<#