-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExchange-Documentation-Script-Enhanced.ps1
More file actions
1275 lines (1100 loc) · 61 KB
/
Exchange-Documentation-Script-Enhanced.ps1
File metadata and controls
1275 lines (1100 loc) · 61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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
Comprehensive Exchange Infrastructure Documentation Script
.DESCRIPTION
This script connects to Exchange On-Premises and/or Exchange Online to generate
comprehensive documentation including ALL configurations, settings, certificates,
and infrastructure details. Outputs both CSV and HTML reports for auditing and analysis.
.PARAMETER Environment
Specifies the environment to document: OnPremises, Online, or Both
.PARAMETER OutputPath
Specifies the output directory for reports (default: current directory)
.PARAMETER ExchangeServer
For on-premises: FQDN of Exchange server to connect to
.PARAMETER Credential
Credentials for authentication (if not provided, will prompt)
.PARAMETER TenantId
Azure AD Tenant ID for Exchange Online connection (optional)
.PARAMETER AppId
Application ID for certificate-based authentication (optional)
.PARAMETER CertificateThumbprint
Certificate thumbprint for certificate-based authentication (optional)
.PARAMETER IncludeDetailedStats
Include detailed mailbox and database statistics (may take longer)
.EXAMPLE
.\Exchange-Documentation-Script-Enhanced.ps1 -Environment Both -OutputPath "C:\Reports" -IncludeDetailedStats
.EXAMPLE
.\Exchange-Documentation-Script-Enhanced.ps1 -Environment Both -OutputPath "C:\Reports"
.EXAMPLE
.\Exchange-Documentation-Script-Enhanced.ps1 -Environment OnPremises -ExchangeServer "exchange01.contoso.com"
.EXAMPLE
.\Exchange-Documentation-Script-Enhanced.ps1 -Environment Online -TenantId "contoso.onmicrosoft.com"
.EXAMPLE
.\Exchange-Documentation-Script-Enhanced.ps1 -Environment Online -AppId "12345678-1234-1234-1234-123456789012" -CertificateThumbprint "ABC123..." -TenantId "contoso.onmicrosoft.com"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[ValidateSet("OnPremises", "Online", "Both")]
[string]$Environment,
[Parameter(Mandatory=$false)]
[string]$OutputPath = (Get-Location).Path,
[Parameter(Mandatory=$false)]
[string]$ExchangeServer,
[Parameter(Mandatory=$false)]
[PSCredential]$Credential,
[Parameter(Mandatory=$false)]
[string]$TenantId,
[Parameter(Mandatory=$false)]
[string]$AppId,
[Parameter(Mandatory=$false)]
[string]$CertificateThumbprint,
[Parameter(Mandatory=$false)]
[switch]$IncludeDetailedStats
)
# Global variables
$Script:ReportData = @{}
$Script:Timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$Script:CSVPath = Join-Path $OutputPath "Exchange_Comprehensive_Documentation_$Script:Timestamp.csv"
$Script:HTMLPath = Join-Path $OutputPath "Exchange_Comprehensive_Documentation_$Script:Timestamp.html"
$Script:ConnectedToEXO = $false
$Script:ConnectedToGraph = $false
# Function to write progress and log
function Write-LogProgress {
param([string]$Message, [string]$Status = "Processing")
Write-Progress -Activity "Exchange Comprehensive Documentation" -Status $Status -CurrentOperation $Message
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss'): $Message" -ForegroundColor Green
}
# Function to safely execute commands and handle errors
function Invoke-SafeCommand {
param(
[scriptblock]$Command,
[string]$Description,
[string]$Category
)
try {
Write-LogProgress "Collecting $Description"
$result = & $Command
if ($result) {
$Script:ReportData[$Category] = $result
}
return $result
}
catch {
Write-Warning "Failed to collect $Description`: $($_.Exception.Message)"
return $null
}
}
# Function to check and install required modules
function Test-RequiredModules {
param([string]$Environment)
$modulesNeeded = @()
if ($Environment -eq "Online" -or $Environment -eq "Both") {
if (-not (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) {
$modulesNeeded += "ExchangeOnlineManagement"
}
if (-not (Get-Module -ListAvailable -Name Microsoft.Graph)) {
Write-Warning "Microsoft.Graph module not found. Some additional data collection will be skipped."
}
}
if ($modulesNeeded.Count -gt 0) {
Write-Host "The following modules are required but not installed:" -ForegroundColor Yellow
$modulesNeeded | ForEach-Object { Write-Host " - $_" -ForegroundColor Yellow }
Write-Host ""
Write-Host "To install these modules, run:" -ForegroundColor Cyan
$modulesNeeded | ForEach-Object { Write-Host " Install-Module -Name $_ -Scope CurrentUser" -ForegroundColor Cyan }
Write-Host ""
$install = Read-Host "Would you like to install these modules now? (Y/N)"
if ($install -eq "Y" -or $install -eq "y") {
foreach ($module in $modulesNeeded) {
try {
Write-LogProgress "Installing module: $module"
Install-Module -Name $module -Scope CurrentUser -Force -AllowClobber
Write-Host "Successfully installed $module" -ForegroundColor Green
}
catch {
Write-Error "Failed to install $module`: $($_.Exception.Message)"
return $false
}
}
} else {
Write-Error "Required modules are not installed. Exiting."
return $false
}
}
return $true
}
# Function to connect to Exchange On-Premises
function Connect-ExchangeOnPremises {
param([string]$Server, [PSCredential]$Cred)
Write-LogProgress "Connecting to Exchange On-Premises: $Server"
try {
if ($Cred) {
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$Server/PowerShell/" -Authentication Kerberos -Credential $Cred
} else {
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$Server/PowerShell/" -Authentication Kerberos
}
Import-PSSession $Session -DisableNameChecking -AllowClobber | Out-Null
Write-LogProgress "Successfully connected to Exchange On-Premises"
return $Session
}
catch {
Write-Error "Failed to connect to Exchange On-Premises: $($_.Exception.Message)"
return $null
}
}
# Function to connect to Exchange Online
function Connect-ExchangeOnline {
param(
[string]$TenantId,
[string]$AppId,
[string]$CertThumbprint
)
Write-LogProgress "Connecting to Exchange Online"
try {
Import-Module ExchangeOnlineManagement -Force
# Determine connection method
if ($AppId -and $CertThumbprint -and $TenantId) {
# Certificate-based authentication
Write-LogProgress "Using certificate-based authentication"
Connect-ExchangeOnline -AppId $AppId -CertificateThumbprint $CertThumbprint -Organization $TenantId -ShowProgress $false
} elseif ($TenantId) {
# Interactive authentication with specific tenant
Write-LogProgress "Using interactive authentication with tenant: $TenantId"
Connect-ExchangeOnline -UserPrincipalName "admin@$TenantId" -ShowProgress $false
} else {
# Standard interactive authentication
Write-LogProgress "Using interactive authentication"
Connect-ExchangeOnline -ShowProgress $false
}
# Test connection
$null = Get-OrganizationConfig -ErrorAction Stop
$Script:ConnectedToEXO = $true
Write-LogProgress "Successfully connected to Exchange Online"
return $true
}
catch {
Write-Error "Failed to connect to Exchange Online: $($_.Exception.Message)"
return $false
}
}
# Function to connect to Microsoft Graph
function Connect-MicrosoftGraph {
param([string]$TenantId)
try {
if (Get-Module -ListAvailable -Name Microsoft.Graph.Authentication) {
Write-LogProgress "Connecting to Microsoft Graph"
Import-Module Microsoft.Graph.Authentication -Force
$scopes = @(
"Directory.Read.All",
"Organization.Read.All",
"Policy.Read.All",
"SecurityEvents.Read.All"
)
if ($TenantId) {
Connect-MgGraph -TenantId $TenantId -Scopes $scopes -NoWelcome
} else {
Connect-MgGraph -Scopes $scopes -NoWelcome
}
$Script:ConnectedToGraph = $true
Write-LogProgress "Successfully connected to Microsoft Graph"
return $true
}
}
catch {
Write-Warning "Could not connect to Microsoft Graph: $($_.Exception.Message)"
return $false
}
}
# Function to collect Exchange On-Premises data
function Get-ExchangeOnPremisesData {
Write-LogProgress "Starting comprehensive Exchange On-Premises data collection"
# Organization Configuration
Invoke-SafeCommand -Command {
Get-OrganizationConfig | Select-Object Name, ExchangeVersion, AdminDisplayVersion, IsDehydrated,
HybridConfigurationStatus, MaxReceiveSize, MaxSendSize, DefaultPublicFolderDatabase,
@{N='CollectedDate';E={Get-Date}}
} -Description "Organization Configuration" -Category "OrganizationConfig"
# Exchange Servers with detailed information
Invoke-SafeCommand -Command {
Get-ExchangeServer | Select-Object Name, ServerRole, AdminDisplayVersion, Edition, FQDN, Site,
IsHubTransportServer, IsClientAccessServer, IsMailboxServer, IsUnifiedMessagingServer, IsEdgeServer,
NetworkAddress, OrganizationalUnit, WhenCreated, WhenChanged,
@{N='CollectedDate';E={Get-Date}}
} -Description "Exchange Servers" -Category "ExchangeServers"
# Exchange Certificates - CRITICAL for SMTP, EWS, etc.
Invoke-SafeCommand -Command {
$certs = @()
$servers = Get-ExchangeServer
foreach ($server in $servers) {
try {
$serverCerts = Get-ExchangeCertificate -Server $server.Name | Select-Object `
@{N='Server';E={$server.Name}}, `
Thumbprint, Subject, Issuer, NotBefore, NotAfter, Status, `
Services, CertificateDomains, IsSelfSigned, HasPrivateKey, `
@{N='DaysUntilExpiry';E={($_.NotAfter - (Get-Date)).Days}}, `
@{N='IsExpired';E={$_.NotAfter -lt (Get-Date)}}, `
@{N='CollectedDate';E={Get-Date}}
$certs += $serverCerts
}
catch {
Write-Warning "Could not retrieve certificates from server $($server.Name): $($_.Exception.Message)"
}
}
return $certs
} -Description "Exchange Certificates" -Category "ExchangeCertificates"
# Database Information with detailed settings
Invoke-SafeCommand -Command {
Get-MailboxDatabase | Select-Object Name, Server, MasterServerOrAvailabilityGroup, EdbFilePath,
LogFolderPath, CircularLoggingEnabled, MaintenanceSchedule, QuotaNotificationSchedule,
ProhibitSendQuota, ProhibitSendReceiveQuota, IssueWarningQuota, DeletedItemRetention,
MailboxRetention, IndexEnabled, BackgroundDatabaseMaintenance, AllowFileRestore,
@{N='CollectedDate';E={Get-Date}}
} -Description "Mailbox Databases" -Category "MailboxDatabases"
# Database Copies and Health
Invoke-SafeCommand -Command {
Get-MailboxDatabaseCopyStatus | Select-Object Name, Status, CopyQueueLength, ReplayQueueLength,
LastInspectedLogTime, ContentIndexState, ActivationSuspended,
@{N='CollectedDate';E={Get-Date}}
} -Description "Database Copy Status" -Category "DatabaseCopyStatus"
# Public Folder Databases (if any)
Invoke-SafeCommand -Command {
Get-PublicFolderDatabase -ErrorAction SilentlyContinue | Select-Object Name, Server, EdbFilePath,
LogFolderPath, MaintenanceSchedule, MaxItemSize, ProhibitPostQuota, IssueWarningQuota,
@{N='CollectedDate';E={Get-Date}}
} -Description "Public Folder Databases" -Category "PublicFolderDatabases"
# Database Availability Groups with detailed configuration
Invoke-SafeCommand -Command {
Get-DatabaseAvailabilityGroup -ErrorAction SilentlyContinue | Select-Object Name, Servers,
WitnessServer, WitnessDirectory, AlternateWitnessServer, NetworkCompression, NetworkEncryption,
ReplicationPort, DatacenterActivationMode, ThirdPartyReplication,
@{N='CollectedDate';E={Get-Date}}
} -Description "Database Availability Groups" -Category "DatabaseAvailabilityGroups"
# Receive Connectors - Including SMTP Relay configurations
Invoke-SafeCommand -Command {
Get-ReceiveConnector | Select-Object Identity, Server, Bindings, RemoteIPRanges, AuthMechanism,
PermissionGroups, MaxMessageSize, ConnectionTimeout, MaxInboundConnection, RequireTLS,
EnableAuthGSSAPI, ExtendedProtectionPolicy, SuppressXAnonymousTls, AdvertiseClientSettings,
Banner, Comment, Enabled, Fqdn, LongAddressesEnabled, OrarEnabled, PipeliningEnabled,
ProtocolLoggingLevel, SizeEnabled, TarpitInterval, TransportRole,
@{N='CollectedDate';E={Get-Date}}
} -Description "Receive Connectors (SMTP Relay)" -Category "ReceiveConnectors"
# Send Connectors - Including SMTP Relay configurations
Invoke-SafeCommand -Command {
Get-SendConnector | Select-Object Identity, AddressSpaces, SourceTransportServers, SmartHosts,
Port, RequireTLS, SmartHostAuthMechanism, UseExternalDNSServersEnabled, MaxMessageSize,
ConnectionInactivityTimeout, DnsRoutingEnabled, ErrorPolicies, ForceHELO, Fqdn,
IgnoreSTARTTLS, IsScopedConnector, IsSmtpConnector, LinkedReceiveConnector, ProtocolLoggingLevel,
SmartHostsString, TlsAuthLevel, TlsCertificateName, TlsDomain,
@{N='CollectedDate';E={Get-Date}}
} -Description "Send Connectors (SMTP Relay)" -Category "SendConnectors"
# Transport Configuration
Invoke-SafeCommand -Command {
Get-TransportConfig | Select-Object MaxDumpsterSizePerDatabase, MaxDumpsterTime,
MaxReceiveSize, MaxSendSize, ExternalPostmasterAddress, GenerateCopyOfDSNFor,
InternalSMTPServers, JournalingReportNdrTo, MaxRecipientEnvelopeLimit,
OrganizationFederatedMailbox, RedirectUnprovisionedUserMessagesTo, ShadowRedundancyEnabled,
@{N='CollectedDate';E={Get-Date}}
} -Description "Transport Configuration" -Category "TransportConfiguration"
# Transport Rules with detailed conditions and actions
Invoke-SafeCommand -Command {
Get-TransportRule | Select-Object Name, Priority, State, Mode, Description, Conditions, Actions,
Exceptions, Comments, RuleVersion, WhenChanged,
@{N='CollectedDate';E={Get-Date}}
} -Description "Transport Rules" -Category "TransportRules"
# Accepted Domains
Invoke-SafeCommand -Command {
Get-AcceptedDomain | Select-Object Name, DomainName, DomainType, Default, MatchSubDomains,
AddressBookEnabled, @{N='CollectedDate';E={Get-Date}}
} -Description "Accepted Domains" -Category "AcceptedDomains"
# Remote Domains
Invoke-SafeCommand -Command {
Get-RemoteDomain | Select-Object Name, DomainName, AllowedOOFType, AutoReplyEnabled,
AutoForwardEnabled, DeliveryReportEnabled, NDREnabled, MeetingForwardNotificationEnabled,
UseSimpleDisplayName, @{N='CollectedDate';E={Get-Date}}
} -Description "Remote Domains" -Category "RemoteDomains"
# Email Address Policies
Invoke-SafeCommand -Command {
Get-EmailAddressPolicy | Select-Object Name, Priority, EnabledEmailAddressTemplates,
RecipientFilter, RecipientContainer, @{N='CollectedDate';E={Get-Date}}
} -Description "Email Address Policies" -Category "EmailAddressPolicies"
# Virtual Directories - Critical for client connectivity
Invoke-SafeCommand -Command {
$vdirs = @()
# OWA Virtual Directories
$vdirs += Get-OwaVirtualDirectory | Select-Object Identity, Server, InternalUrl, ExternalUrl,
@{N='Type';E={'OWA'}}, DefaultDomain, LogonFormat, ClientAuthCleanupLevel,
ExternalAuthenticationMethods, InternalAuthenticationMethods, WindowsAuthentication,
@{N='CollectedDate';E={Get-Date}}
# ECP Virtual Directories
$vdirs += Get-EcpVirtualDirectory | Select-Object Identity, Server, InternalUrl, ExternalUrl,
@{N='Type';E={'ECP'}}, ExternalAuthenticationMethods, InternalAuthenticationMethods,
@{N='CollectedDate';E={Get-Date}}
# ActiveSync Virtual Directories
$vdirs += Get-ActiveSyncVirtualDirectory | Select-Object Identity, Server, InternalUrl, ExternalUrl,
@{N='Type';E={'ActiveSync'}}, ExternalAuthenticationMethods, InternalAuthenticationMethods,
ClientCertAuth, CompressionEnabled, WindowsAuthEnabled,
@{N='CollectedDate';E={Get-Date}}
# EWS Virtual Directories - CRITICAL
$vdirs += Get-WebServicesVirtualDirectory | Select-Object Identity, Server, InternalUrl, ExternalUrl,
@{N='Type';E={'EWS'}}, CertificateAuthentication, WSSecurityAuthentication, OAuthAuthentication,
ExternalAuthenticationMethods, InternalAuthenticationMethods, WindowsAuthentication,
@{N='CollectedDate';E={Get-Date}}
# OAB Virtual Directories
$vdirs += Get-OabVirtualDirectory | Select-Object Identity, Server, InternalUrl, ExternalUrl,
@{N='Type';E={'OAB'}}, ExternalAuthenticationMethods, InternalAuthenticationMethods,
RequireSSL, @{N='CollectedDate';E={Get-Date}}
# Autodiscover Virtual Directories
$vdirs += Get-AutodiscoverVirtualDirectory | Select-Object Identity, Server, InternalUrl, ExternalUrl,
@{N='Type';E={'Autodiscover'}}, ExternalAuthenticationMethods, InternalAuthenticationMethods,
WindowsAuthentication, WSSecurityAuthentication,
@{N='CollectedDate';E={Get-Date}}
# MAPI Virtual Directories
$vdirs += Get-MapiVirtualDirectory -ErrorAction SilentlyContinue | Select-Object Identity, Server, InternalUrl, ExternalUrl,
@{N='Type';E={'MAPI'}}, ExternalAuthenticationMethods, InternalAuthenticationMethods,
@{N='CollectedDate';E={Get-Date}}
# PowerShell Virtual Directories
$vdirs += Get-PowerShellVirtualDirectory | Select-Object Identity, Server, InternalUrl, ExternalUrl,
@{N='Type';E={'PowerShell'}}, ExternalAuthenticationMethods, InternalAuthenticationMethods,
RequireSSL, CertificateAuthentication,
@{N='CollectedDate';E={Get-Date}}
return $vdirs
} -Description "Virtual Directories (OWA, EWS, ActiveSync, etc.)" -Category "VirtualDirectories"
# Client Access Services
Invoke-SafeCommand -Command {
Get-ClientAccessService | Select-Object Name, Server, AutoDiscoverServiceInternalUri,
AutoDiscoverSiteScope, AlternateServiceAccountConfiguration,
@{N='CollectedDate';E={Get-Date}}
} -Description "Client Access Services" -Category "ClientAccessServices"
# Outlook Anywhere Configuration
Invoke-SafeCommand -Command {
Get-OutlookAnywhere | Select-Object Identity, Server, InternalHostname, ExternalHostname,
InternalClientAuthenticationMethod, ExternalClientAuthenticationMethod, IISAuthenticationMethods,
SSLOffloading, ExternalClientsRequireSsl, InternalClientsRequireSsl,
@{N='CollectedDate';E={Get-Date}}
} -Description "Outlook Anywhere (RPC over HTTP)" -Category "OutlookAnywhere"
# Federation Trust and Organization Relationships
Invoke-SafeCommand -Command {
Get-FederationTrust -ErrorAction SilentlyContinue | Select-Object Name, ApplicationUri,
TokenIssuerUris, OrgCertificate, TokenIssuerCertificate, TokenIssuerPrevCertificate,
@{N='CollectedDate';E={Get-Date}}
} -Description "Federation Trust" -Category "FederationTrust"
Invoke-SafeCommand -Command {
Get-OrganizationRelationship -ErrorAction SilentlyContinue | Select-Object Name, DomainNames,
FreeBusyAccessEnabled, FreeBusyAccessLevel, FreeBusyAccessScope, MailboxMoveEnabled,
DeliveryReportEnabled, MailTipsAccessEnabled, MailTipsAccessLevel, MailTipsAccessScope,
@{N='CollectedDate';E={Get-Date}}
} -Description "Organization Relationships" -Category "OrganizationRelationships"
# Sharing Policies
Invoke-SafeCommand -Command {
Get-SharingPolicy | Select-Object Name, Domains, Enabled, Default,
@{N='CollectedDate';E={Get-Date}}
} -Description "Sharing Policies" -Category "SharingPolicies"
# Retention Policies and Tags
Invoke-SafeCommand -Command {
Get-RetentionPolicy | Select-Object Name, RetentionPolicyTagLinks, IsDefault,
@{N='CollectedDate';E={Get-Date}}
} -Description "Retention Policies" -Category "RetentionPolicies"
Invoke-SafeCommand -Command {
Get-RetentionPolicyTag | Select-Object Name, Type, RetentionEnabled, AgeLimitForRetention,
RetentionAction, MessageClass, @{N='CollectedDate';E={Get-Date}}
} -Description "Retention Policy Tags" -Category "RetentionPolicyTags"
# Address Lists and Global Address Lists
Invoke-SafeCommand -Command {
Get-AddressList | Select-Object Name, RecipientFilter, RecipientContainer, DisplayName,
@{N='CollectedDate';E={Get-Date}}
} -Description "Address Lists" -Category "AddressLists"
Invoke-SafeCommand -Command {
Get-GlobalAddressList | Select-Object Name, RecipientFilter, RecipientContainer,
@{N='CollectedDate';E={Get-Date}}
} -Description "Global Address Lists" -Category "GlobalAddressLists"
# Offline Address Books
Invoke-SafeCommand -Command {
Get-OfflineAddressBook | Select-Object Name, AddressLists, Server, PublicFolderDatabase,
Schedule, IsDefault, @{N='CollectedDate';E={Get-Date}}
} -Description "Offline Address Books" -Category "OfflineAddressBooks"
# Mailbox Statistics Summary
Invoke-SafeCommand -Command {
$mailboxes = Get-Mailbox -ResultSize Unlimited
$stats = @{
TotalMailboxes = $mailboxes.Count
UserMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'UserMailbox'}).Count
SharedMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'SharedMailbox'}).Count
ResourceMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -like '*Resource*'}).Count
RoomMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'RoomMailbox'}).Count
EquipmentMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'EquipmentMailbox'}).Count
LinkedMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'LinkedMailbox'}).Count
CollectedDate = Get-Date
}
return [PSCustomObject]$stats
} -Description "Mailbox Statistics" -Category "MailboxStatistics"
# Detailed Mailbox Statistics (if requested)
if ($IncludeDetailedStats) {
Invoke-SafeCommand -Command {
Write-LogProgress "Collecting detailed mailbox statistics (this will take time)"
$mailboxStats = @()
$mailboxes = Get-Mailbox -ResultSize 100 # Limit for performance
foreach ($mailbox in $mailboxes) {
try {
$stats = Get-MailboxStatistics $mailbox.Identity
$mailboxStats += [PSCustomObject]@{
DisplayName = $mailbox.DisplayName
PrimarySmtpAddress = $mailbox.PrimarySmtpAddress
RecipientTypeDetails = $mailbox.RecipientTypeDetails
Database = $stats.Database
TotalItemSize = $stats.TotalItemSize
ItemCount = $stats.ItemCount
DeletedItemCount = $stats.DeletedItemCount
LastLogonTime = $stats.LastLogonTime
LastLoggedOnUserAccount = $stats.LastLoggedOnUserAccount
CollectedDate = Get-Date
}
}
catch {
Write-Warning "Could not get statistics for mailbox $($mailbox.DisplayName)"
}
}
return $mailboxStats
} -Description "Detailed Mailbox Statistics (Sample)" -Category "DetailedMailboxStats"
}
# Hybrid Configuration (if exists)
Invoke-SafeCommand -Command {
Get-HybridConfiguration -ErrorAction SilentlyContinue | Select-Object Identity,
OnPremisesSmartHost, Domains, Features, TlsCertificateName, EdgeTransportServers,
ReceivingTransportServers, SendingTransportServers, ClientAccessServers,
@{N='CollectedDate';E={Get-Date}}
} -Description "Hybrid Configuration" -Category "HybridConfiguration"
# Edge Synchronization (if applicable)
Invoke-SafeCommand -Command {
Get-EdgeSubscription -ErrorAction SilentlyContinue | Select-Object Name, Site, Domain,
CreateDate, @{N='CollectedDate';E={Get-Date}}
} -Description "Edge Subscriptions" -Category "EdgeSubscriptions"
# Message Classifications
Invoke-SafeCommand -Command {
Get-MessageClassification -ErrorAction SilentlyContinue | Select-Object Name, DisplayName,
SenderDescription, RecipientDescription, ClassificationID,
@{N='CollectedDate';E={Get-Date}}
} -Description "Message Classifications" -Category "MessageClassifications"
# Throttling Policies
Invoke-SafeCommand -Command {
Get-ThrottlingPolicy | Select-Object Name, IsDefault, AnonymousMaxConcurrency,
EasMaxConcurrency, EwsMaxConcurrency, ImapMaxConcurrency, OutlookServiceMaxConcurrency,
OwaMaxConcurrency, PopMaxConcurrency, PowerShellMaxConcurrency, RcaMaxConcurrency,
@{N='CollectedDate';E={Get-Date}}
} -Description "Throttling Policies" -Category "ThrottlingPolicies"
# Mobile Device Mailbox Policies
Invoke-SafeCommand -Command {
Get-ActiveSyncMailboxPolicy | Select-Object Name, AllowNonProvisionableDevices,
PasswordEnabled, AlphanumericPasswordRequired, PasswordRecoveryEnabled, DeviceEncryptionEnabled,
AttachmentsEnabled, MaxAttachmentSize, AllowStorageCard, AllowCamera, AllowWiFi, AllowBluetooth,
@{N='CollectedDate';E={Get-Date}}
} -Description "Mobile Device Mailbox Policies" -Category "MobileDeviceMailboxPolicies"
# OWA Mailbox Policies
Invoke-SafeCommand -Command {
Get-OwaMailboxPolicy | Select-Object Name, DirectFileAccessOnPublicComputersEnabled,
DirectFileAccessOnPrivateComputersEnabled, WebReadyDocumentViewingOnPublicComputersEnabled,
ForceWebReadyDocumentViewingFirstOnPublicComputers, ActiveSyncIntegrationEnabled,
AllowOfflineOn, ExternalImageProxyEnabled, @{N='CollectedDate';E={Get-Date}}
} -Description "OWA Mailbox Policies" -Category "OWAMailboxPolicies"
# Journal Rules
Invoke-SafeCommand -Command {
Get-JournalRule | Select-Object Name, JournalEmailAddress, Scope, Recipient, Enabled,
@{N='CollectedDate';E={Get-Date}}
} -Description "Journal Rules" -Category "JournalRules"
# Management Role Assignments (Security)
Invoke-SafeCommand -Command {
Get-ManagementRoleAssignment | Select-Object Name, Role, RoleAssignee, RoleAssigneeType,
AssignmentMethod, IsValid, @{N='CollectedDate';E={Get-Date}}
} -Description "Management Role Assignments" -Category "ManagementRoleAssignments"
Write-LogProgress "Completed comprehensive Exchange On-Premises data collection"
}
# Function to collect Exchange Online data
function Get-ExchangeOnlineData {
Write-LogProgress "Starting comprehensive Exchange Online data collection"
# Organization Configuration
Invoke-SafeCommand -Command {
Get-OrganizationConfig | Select-Object Name, DisplayName, DefaultMailTip, MailTipsAllTipsEnabled,
MailTipsExternalRecipientsTipsEnabled, MailTipsGroupMetricsEnabled, MailTipsLargeAudienceThreshold,
IsDehydrated, HybridConfigurationStatus, MaxReceiveSize, MaxSendSize,
@{N='CollectedDate';E={Get-Date}}
} -Description "Organization Configuration" -Category "EXO_OrganizationConfig"
# Tenant Information
Invoke-SafeCommand -Command {
$tenant = Get-OrganizationConfig
$tenantInfo = @{
TenantName = $tenant.Name
DisplayName = $tenant.DisplayName
DefaultDomain = (Get-AcceptedDomain | Where-Object {$_.Default -eq $true}).DomainName
TotalDomains = (Get-AcceptedDomain).Count
ExchangeVersion = $tenant.AdminDisplayVersion
IsDehydrated = $tenant.IsDehydrated
HybridConfigurationStatus = $tenant.HybridConfigurationStatus
CollectedDate = Get-Date
}
return [PSCustomObject]$tenantInfo
} -Description "Tenant Information" -Category "EXO_TenantInfo"
# Mailbox Plans
Invoke-SafeCommand -Command {
Get-MailboxPlan | Select-Object DisplayName, MaxSendSize, MaxReceiveSize, ProhibitSendQuota,
ProhibitSendReceiveQuota, IssueWarningQuota, RetainDeletedItemsFor, RoleAssignmentPolicy,
@{N='CollectedDate';E={Get-Date}}
} -Description "Mailbox Plans" -Category "EXO_MailboxPlans"
# Accepted Domains
Invoke-SafeCommand -Command {
Get-AcceptedDomain | Select-Object Name, DomainName, DomainType, Default, MatchSubDomains,
AddressBookEnabled, @{N='CollectedDate';E={Get-Date}}
} -Description "Accepted Domains" -Category "EXO_AcceptedDomains"
# Remote Domains
Invoke-SafeCommand -Command {
Get-RemoteDomain | Select-Object Name, DomainName, AllowedOOFType, AutoReplyEnabled,
AutoForwardEnabled, DeliveryReportEnabled, NDREnabled, MeetingForwardNotificationEnabled,
UseSimpleDisplayName, @{N='CollectedDate';E={Get-Date}}
} -Description "Remote Domains" -Category "EXO_RemoteDomains"
# Transport Configuration
Invoke-SafeCommand -Command {
Get-TransportConfig | Select-Object MaxReceiveSize, MaxSendSize, ExternalPostmasterAddress,
GenerateCopyOfDSNFor, JournalingReportNdrTo, MaxRecipientEnvelopeLimit,
OrganizationFederatedMailbox, RedirectUnprovisionedUserMessagesTo,
@{N='CollectedDate';E={Get-Date}}
} -Description "Transport Configuration" -Category "EXO_TransportConfiguration"
# Transport Rules
Invoke-SafeCommand -Command {
Get-TransportRule | Select-Object Name, Priority, State, Mode, Description, Comments,
RuleVersion, WhenChanged, @{N='CollectedDate';E={Get-Date}}
} -Description "Transport Rules" -Category "EXO_TransportRules"
# Inbound Connectors - SMTP Relay for Exchange Online
Invoke-SafeCommand -Command {
Get-InboundConnector | Select-Object Name, ConnectorType, ConnectorSource, SenderDomains,
SenderIPAddresses, RequireTls, RestrictDomainsToIPAddresses, Enabled, Comment,
TlsSenderCertificateName, CloudServicesMailEnabled, TreatMessagesAsInternal,
@{N='CollectedDate';E={Get-Date}}
} -Description "Inbound Connectors (SMTP Relay)" -Category "EXO_InboundConnectors"
# Outbound Connectors - SMTP Relay for Exchange Online
Invoke-SafeCommand -Command {
Get-OutboundConnector | Select-Object Name, ConnectorType, RecipientDomains, SmartHosts,
TlsDomain, UseMxRecord, RouteAllMessagesViaOnPremises, Enabled, Comment,
TlsSettings, IsTransportRuleScoped, CloudServicesMailEnabled, AllAcceptedDomains,
@{N='CollectedDate';E={Get-Date}}
} -Description "Outbound Connectors (SMTP Relay)" -Category "EXO_OutboundConnectors"
# Anti-Spam Policies (Exchange Online Protection)
Invoke-SafeCommand -Command {
Get-HostedContentFilterPolicy | Select-Object Name, SpamAction, HighConfidenceSpamAction,
PhishSpamAction, BulkSpamAction, QuarantineRetentionPeriod, EndUserSpamNotificationFrequency,
TestModeAction, IncreaseScoreWithImageLinks, IncreaseScoreWithNumericIps,
IncreaseScoreWithRedirectToOtherPort, IncreaseScoreWithBizOrInfoUrls,
@{N='CollectedDate';E={Get-Date}}
} -Description "Anti-Spam Policies (EOP)" -Category "EXO_AntiSpamPolicies"
# Anti-Malware Policies (Exchange Online Protection)
Invoke-SafeCommand -Command {
Get-MalwareFilterPolicy | Select-Object Name, Action, EnableFileFilter, FileTypes,
EnableInternalSenderAdminNotifications, EnableInternalSenderNotifications,
InternalSenderAdminAddress, CustomNotifications, CustomFromAddress, CustomFromName,
@{N='CollectedDate';E={Get-Date}}
} -Description "Anti-Malware Policies (EOP)" -Category "EXO_AntiMalwarePolicies"
# Connection Filter Policies (IP Allow/Block Lists)
Invoke-SafeCommand -Command {
Get-HostedConnectionFilterPolicy | Select-Object Name, IPAllowList, IPBlockList,
EnableSafeList, DirectoryBasedEdgeBlockMode, @{N='CollectedDate';E={Get-Date}}
} -Description "Connection Filter Policies (IP Lists)" -Category "EXO_ConnectionFilterPolicies"
# Safe Attachments Policies (Defender for Office 365)
Invoke-SafeCommand -Command {
Get-SafeAttachmentPolicy -ErrorAction SilentlyContinue | Select-Object Name, Enable, Action,
Redirect, RedirectAddress, ActionOnError, @{N='CollectedDate';E={Get-Date}}
} -Description "Safe Attachments Policies (Defender)" -Category "EXO_SafeAttachmentPolicies"
# Safe Links Policies (Defender for Office 365)
Invoke-SafeCommand -Command {
Get-SafeLinksPolicy -ErrorAction SilentlyContinue | Select-Object Name, IsEnabled,
ScanUrls, EnableForInternalSenders, TrackClicks, AllowClickThrough, EnableSafeLinksForTeams,
@{N='CollectedDate';E={Get-Date}}
} -Description "Safe Links Policies (Defender)" -Category "EXO_SafeLinksPolicies"
# ATP Policies (Defender for Office 365)
Invoke-SafeCommand -Command {
Get-AtpPolicyForO365 -ErrorAction SilentlyContinue | Select-Object Name, EnableATPForSPOTeamsODB,
EnableSafeDocs, AllowSafeDocsOpen, @{N='CollectedDate';E={Get-Date}}
} -Description "ATP Policies (Defender)" -Category "EXO_ATPPolicies"
# Anti-Phishing Policies
Invoke-SafeCommand -Command {
Get-AntiPhishPolicy -ErrorAction SilentlyContinue | Select-Object Name, Enabled,
EnableMailboxIntelligence, EnableMailboxIntelligenceProtection, EnableSpoofIntelligence,
EnableFirstContactSafetyTips, EnableSimilarUsersSafetyTips, EnableSimilarDomainsSafetyTips,
EnableUnusualCharactersSafetyTips, @{N='CollectedDate';E={Get-Date}}
} -Description "Anti-Phishing Policies" -Category "EXO_AntiPhishingPolicies"
# DKIM Configuration
Invoke-SafeCommand -Command {
$domains = Get-AcceptedDomain | Where-Object {$_.DomainType -ne "InternalRelay"}
$dkimConfig = @()
foreach ($domain in $domains) {
try {
$dkim = Get-DkimSigningConfig -Identity $domain.DomainName -ErrorAction SilentlyContinue
if ($dkim) {
$dkimConfig += $dkim | Select-Object Domain, Enabled, Status, Selector1CNAME,
Selector2CNAME, @{N='CollectedDate';E={Get-Date}}
}
}
catch {
# Domain might not support DKIM
}
}
return $dkimConfig
} -Description "DKIM Configuration" -Category "EXO_DKIMConfiguration"
# Detailed Mailbox Statistics
Invoke-SafeCommand -Command {
Write-LogProgress "Collecting detailed mailbox statistics (this may take a while)"
$mailboxes = Get-EXOMailbox -ResultSize Unlimited -PropertySets Minimum
$stats = @{
TotalMailboxes = $mailboxes.Count
UserMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'UserMailbox'}).Count
SharedMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'SharedMailbox'}).Count
ResourceMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -like '*Resource*'}).Count
EquipmentMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'EquipmentMailbox'}).Count
RoomMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'RoomMailbox'}).Count
DiscoveryMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'DiscoveryMailbox'}).Count
GroupMailboxes = ($mailboxes | Where-Object {$_.RecipientTypeDetails -eq 'GroupMailbox'}).Count
CollectedDate = Get-Date
}
return [PSCustomObject]$stats
} -Description "Mailbox Statistics" -Category "EXO_MailboxStatistics"
# Distribution Groups Statistics
Invoke-SafeCommand -Command {
$groups = Get-DistributionGroup -ResultSize Unlimited
$groupStats = @{
TotalDistributionGroups = $groups.Count
SecurityGroups = ($groups | Where-Object {$_.GroupType -like '*Security*'}).Count
UniversalGroups = ($groups | Where-Object {$_.GroupType -like '*Universal*'}).Count
DynamicGroups = (Get-DynamicDistributionGroup -ResultSize Unlimited).Count
CollectedDate = Get-Date
}
return [PSCustomObject]$groupStats
} -Description "Distribution Group Statistics" -Category "EXO_DistributionGroupStats"
# Mobile Device Access Rules
Invoke-SafeCommand -Command {
Get-ActiveSyncDeviceAccessRule | Select-Object Identity, Characteristic, QueryString,
AccessLevel, @{N='CollectedDate';E={Get-Date}}
} -Description "Mobile Device Access Rules" -Category "EXO_MobileDeviceRules"
# Mobile Device Mailbox Policies
Invoke-SafeCommand -Command {
Get-ActiveSyncMailboxPolicy | Select-Object Name, AllowNonProvisionableDevices,
PasswordEnabled, AlphanumericPasswordRequired, PasswordRecoveryEnabled, DeviceEncryptionEnabled,
AttachmentsEnabled, MaxAttachmentSize, AllowStorageCard, AllowCamera, AllowWiFi, AllowBluetooth,
@{N='CollectedDate';E={Get-Date}}
} -Description "Mobile Device Mailbox Policies" -Category "EXO_MobileDevicePolicies"
# OWA Policies
Invoke-SafeCommand -Command {
Get-OwaMailboxPolicy | Select-Object Name, DirectFileAccessOnPublicComputersEnabled,
DirectFileAccessOnPrivateComputersEnabled, WebReadyDocumentViewingOnPublicComputersEnabled,
ForceWebReadyDocumentViewingFirstOnPublicComputers, ActiveSyncIntegrationEnabled,
AllowOfflineOn, ExternalImageProxyEnabled, @{N='CollectedDate';E={Get-Date}}
} -Description "OWA Policies" -Category "EXO_OWAPolicies"
# Retention Policies
Invoke-SafeCommand -Command {
Get-RetentionPolicy | Select-Object Name, RetentionPolicyTagLinks, IsDefault,
@{N='CollectedDate';E={Get-Date}}
} -Description "Retention Policies" -Category "EXO_RetentionPolicies"
# Data Loss Prevention Policies
Invoke-SafeCommand -Command {
Get-DlpPolicy -ErrorAction SilentlyContinue | Select-Object Name, State, Mode, Description,
@{N='CollectedDate';E={Get-Date}}
} -Description "DLP Policies" -Category "EXO_DLPPolicies"
# Quarantine Policies
Invoke-SafeCommand -Command {
Get-QuarantinePolicy -ErrorAction SilentlyContinue | Select-Object Name,
EndUserQuarantinePermissionsValue, ESNEnabled, @{N='CollectedDate';E={Get-Date}}
} -Description "Quarantine Policies" -Category "EXO_QuarantinePolicies"
# Address Lists
Invoke-SafeCommand -Command {
Get-AddressList | Select-Object Name, RecipientFilter, DisplayName,
@{N='CollectedDate';E={Get-Date}}
} -Description "Address Lists" -Category "EXO_AddressLists"
# Global Address Lists
Invoke-SafeCommand -Command {
Get-GlobalAddressList | Select-Object Name, RecipientFilter,
@{N='CollectedDate';E={Get-Date}}
} -Description "Global Address Lists" -Category "EXO_GlobalAddressLists"
# Offline Address Books
Invoke-SafeCommand -Command {
Get-OfflineAddressBook | Select-Object Name, AddressLists, IsDefault,
@{N='CollectedDate';E={Get-Date}}
} -Description "Offline Address Books" -Category "EXO_OfflineAddressBooks"
# Organization Relationships (Federation)
Invoke-SafeCommand -Command {
Get-OrganizationRelationship | Select-Object Name, DomainNames,
FreeBusyAccessEnabled, FreeBusyAccessLevel, FreeBusyAccessScope, MailboxMoveEnabled,
DeliveryReportEnabled, MailTipsAccessEnabled, MailTipsAccessLevel, MailTipsAccessScope,
@{N='CollectedDate';E={Get-Date}}
} -Description "Organization Relationships" -Category "EXO_OrganizationRelationships"
# Sharing Policies
Invoke-SafeCommand -Command {
Get-SharingPolicy | Select-Object Name, Domains, Enabled, Default,
@{N='CollectedDate';E={Get-Date}}
} -Description "Sharing Policies" -Category "EXO_SharingPolicies"
# Role Assignment Policies
Invoke-SafeCommand -Command {
Get-RoleAssignmentPolicy | Select-Object Name, Description, IsDefault, AssignedRoles,
@{N='CollectedDate';E={Get-Date}}
} -Description "Role Assignment Policies" -Category "EXO_RoleAssignmentPolicies"
# Audit Configuration
Invoke-SafeCommand -Command {
Get-AdminAuditLogConfig | Select-Object AdminAuditLogEnabled, AdminAuditLogCmdlets,
AdminAuditLogParameters, AdminAuditLogExcludedCmdlets, LogLevel,
@{N='CollectedDate';E={Get-Date}}
} -Description "Admin Audit Log Configuration" -Category "EXO_AdminAuditConfig"
# Microsoft Graph data (if connected)
if ($Script:ConnectedToGraph) {
Invoke-SafeCommand -Command {
Import-Module Microsoft.Graph.Identity.DirectoryManagement -Force
$org = Get-MgOrganization
$orgInfo = @{
DisplayName = $org.DisplayName
TenantType = $org.TenantType
CountryLetterCode = $org.CountryLetterCode
CreatedDateTime = $org.CreatedDateTime
TechnicalNotificationMails = $org.TechnicalNotificationMails -join ", "
CollectedDate = Get-Date
}
return [PSCustomObject]$orgInfo
} -Description "Azure AD Organization Info" -Category "AAD_OrganizationInfo"
}
Write-LogProgress "Completed comprehensive Exchange Online data collection"
}
# Function to export data to CSV
function Export-ToCSV {
Write-LogProgress "Exporting data to CSV format"
$csvData = @()
foreach ($category in $Script:ReportData.Keys) {
$data = $Script:ReportData[$category]
if ($data -is [Array]) {
foreach ($item in $data) {
$csvRow = [PSCustomObject]@{
Category = $category
Data = ($item | ConvertTo-Json -Compress)
CollectedDate = Get-Date
}
$csvData += $csvRow
}
} else {
$csvRow = [PSCustomObject]@{
Category = $category
Data = ($data | ConvertTo-Json -Compress)
CollectedDate = Get-Date
}
$csvData += $csvRow
}
}
$csvData | Export-Csv -Path $Script:CSVPath -NoTypeInformation -Encoding UTF8
Write-LogProgress "CSV report saved to: $Script:CSVPath"
}
# Function to generate HTML report
function Export-ToHTML {
Write-LogProgress "Generating comprehensive HTML report"
# Determine environment type for report title
$envType = switch ($Environment) {
"OnPremises" { "On-Premises Exchange" }
"Online" { "Exchange Online" }
"Both" { "Hybrid Exchange Environment" }
}
$htmlContent = @"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>$envType Comprehensive Infrastructure Documentation</title>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; padding: 20px; background-color: #f5f5f5; }
.container { max-width: 1400px; margin: 0 auto; background-color: white; padding: 30px; border-radius: 10px; box-shadow: 0 0 20px rgba(0,0,0,0.1); }
h1 { color: #2c3e50; text-align: center; margin-bottom: 30px; border-bottom: 3px solid #3498db; padding-bottom: 10px; }
h2 { color: #34495e; margin-top: 30px; margin-bottom: 15px; padding: 10px; background-color: #ecf0f1; border-left: 5px solid #3498db; }
h3 { color: #2c3e50; margin-top: 20px; margin-bottom: 10px; }
.info-box { background-color: #e8f4fd; border: 1px solid #bee5eb; border-radius: 5px; padding: 15px; margin: 10px 0; }
.warning-box { background-color: #fff3cd; border: 1px solid #ffeaa7; border-radius: 5px; padding: 15px; margin: 10px 0; }
.success-box { background-color: #d4edda; border: 1px solid #c3e6cb; border-radius: 5px; padding: 15px; margin: 10px 0; }
.critical-box { background-color: #f8d7da; border: 1px solid #f5c6cb; border-radius: 5px; padding: 15px; margin: 10px 0; }
.online-box { background-color: #e1f5fe; border: 1px solid #81d4fa; border-radius: 5px; padding: 15px; margin: 10px 0; }
.onprem-box { background-color: #f3e5f5; border: 1px solid #ce93d8; border-radius: 5px; padding: 15px; margin: 10px 0; }
table { width: 100%; border-collapse: collapse; margin: 15px 0; background-color: white; font-size: 0.9em; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #3498db; color: white; font-weight: bold; }
tr:nth-child(even) { background-color: #f8f9fa; }
tr:hover { background-color: #e8f4fd; }
.timestamp { color: #7f8c8d; font-style: italic; text-align: center; margin-top: 30px; }
.summary-stats { display: flex; justify-content: space-around; margin: 20px 0; flex-wrap: wrap; }
.stat-box { background-color: #3498db; color: white; padding: 20px; border-radius: 10px; text-align: center; min-width: 150px; margin: 5px; }
.stat-box.online { background-color: #2196f3; }
.stat-box.onprem { background-color: #9c27b0; }
.stat-box.critical { background-color: #e74c3c; }
.stat-box.warning { background-color: #f39c12; }
.stat-number { font-size: 2em; font-weight: bold; }
.stat-label { font-size: 0.9em; margin-top: 5px; }
.no-data { color: #7f8c8d; font-style: italic; text-align: center; padding: 20px; }
.collapsible { background-color: #3498db; color: white; cursor: pointer; padding: 15px; width: 100%; border: none; text-align: left; outline: none; font-size: 16px; margin-top: 10px; }
.collapsible:hover { background-color: #2980b9; }
.collapsible.online { background-color: #2196f3; }
.collapsible.online:hover { background-color: #1976d2; }
.collapsible.onprem { background-color: #9c27b0; }
.collapsible.onprem:hover { background-color: #7b1fa2; }
.collapsible.critical { background-color: #e74c3c; }
.collapsible.critical:hover { background-color: #c0392b; }
.content { padding: 0; display: none; overflow: hidden; background-color: #f8f9fa; }
.content.show { display: block; padding: 15px; }
.environment-badge { display: inline-block; padding: 5px 10px; border-radius: 15px; font-size: 0.8em; font-weight: bold; margin-left: 10px; }
.badge-online { background-color: #2196f3; color: white; }
.badge-onprem { background-color: #9c27b0; color: white; }
.badge-critical { background-color: #e74c3c; color: white; }
.cert-expired { background-color: #ffebee; color: #c62828; }
.cert-expiring { background-color: #fff3e0; color: #ef6c00; }
.cert-valid { background-color: #e8f5e8; color: #2e7d32; }
</style>
<script>
function toggleContent(element) {
var content = element.nextElementSibling;
content.classList.toggle('show');
element.textContent = content.classList.contains('show') ?
element.textContent.replace('▶', '▼') :
element.textContent.replace('▼', '▶');
}
</script>
</head>
<body>
<div class="container">
<h1>$envType Comprehensive Infrastructure Documentation</h1>
<div class="info-box">
<strong>Report Generated:</strong> $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')<br>
<strong>Environment:</strong> $Environment<br>
<strong>Total Categories:</strong> $($Script:ReportData.Keys.Count)<br>
<strong>Exchange Online Connected:</strong> $Script:ConnectedToEXO<br>