Src/Private/Get-AbrExoTenantOverview.ps1

function Get-AbrExoTenantOverview {
    <#
    .SYNOPSIS
    Documents Exchange Online tenant-level organisation and accepted domain configuration.
    .NOTES
        Version: 0.1.0
        Author: Pai Wei Sing
    #>

    [CmdletBinding()]
    param (
        [Parameter(Position = 0, Mandatory)]
        [string]$TenantId
    )

    begin {
        Write-PScriboMessage -Message "Collecting Exchange Online Tenant Overview for $TenantId."
        Show-AbrDebugExecutionTime -Start -TitleMessage 'TenantOverview'
    }

    process {
        Section -Style Heading2 'Overview' {
            Paragraph "The following section documents the Exchange Online tenant configuration for $TenantId."
            BlankLine

            #region Organisation Configuration
            try {
                Write-Host " - Retrieving Organisation configuration..."
                $OrgConfig = Get-OrganizationConfig -ErrorAction Stop

                $OrgObj = [System.Collections.ArrayList]::new()
                $orgInObj = [ordered] @{
                    'Display Name'                  = $OrgConfig.DisplayName
                    'Exchange GUID'                 = $OrgConfig.ExchangeObjectId
                    'Directory Synchronisation'     = if ($OrgConfig.IsDirSynced) { 'Enabled (Synced from on-premises AD)' } else { 'Cloud Only (Entra ID native)' }
                    'External Recipient Limit (hr)' = if ($OrgConfig.RecipientLimitExternal) { $OrgConfig.RecipientLimitExternal } else { 'Unlimited' }
                    'Internal Recipient Limit (hr)' = if ($OrgConfig.RecipientLimitInternal) { $OrgConfig.RecipientLimitInternal } else { 'Unlimited' }
                    'Audit Disabled'                = if ($OrgConfig.AuditDisabled) { 'Yes' } else { 'No' }
                    'OAuth Enabled'                 = if ($OrgConfig.OAuth2ClientProfileEnabled) { 'Yes' } else { 'No' }
                    'Mailtips Enabled'              = if ($OrgConfig.MailTipsAllTipsEnabled) { 'Yes' } else { 'No' }
                    'Large Audience Threshold'      = $OrgConfig.MailTipsLargeAudienceThreshold
                }
                $OrgObj.Add([pscustomobject]$orgInObj) | Out-Null

                Section -Style Heading3 'Organisation Configuration' {
                    $OrgTableParams = @{ Name = "Organisation Configuration - $TenantId"; List = $true; ColumnWidths = 40, 60 }
                    if ($Report.ShowTableCaptions) { $OrgTableParams['Caption'] = "- $($OrgTableParams.Name)" }
                    $OrgObj | Table @OrgTableParams
                }

                $script:ExcelSheets['Organisation Config'] = $OrgObj
            } catch {
                Write-ExoError 'TenantOverview' "Unable to retrieve Organisation configuration: $($_.Exception.Message)"
                Paragraph "Unable to retrieve Organisation configuration: $($_.Exception.Message)"
            }
            #endregion

            #region Accepted Domains
            try {
                Write-Host " - Retrieving Accepted Domains..."
                $AcceptedDomains = Get-AcceptedDomain -ErrorAction Stop | Sort-Object Name

                if ($AcceptedDomains) {
                    Section -Style Heading3 'Accepted Domains' {
                        Paragraph "The following $(@($AcceptedDomains).Count) domain(s) are accepted for email delivery in tenant $TenantId."
                        BlankLine

                        $DomainObj = [System.Collections.ArrayList]::new()
                        foreach ($Domain in $AcceptedDomains) {
                            $domainInObj = [ordered] @{
                                'Domain Name'    = $Domain.DomainName
                                'Domain Type'    = $Domain.DomainType
                                'Default'        = if ($Domain.Default) { 'Yes' } else { 'No' }
                                'Authoritative'  = if ($Domain.AuthenticationType -eq 'Authoritative') { 'Yes' } else { 'No' }
                                'Email Only'     = if ($Domain.EmailOnly) { 'Yes' } else { 'No' }
                            }
                            $DomainObj.Add([pscustomobject](ConvertTo-HashToYN $domainInObj)) | Out-Null
                        }

                        $DomainTableParams = @{ Name = "Accepted Domains - $TenantId"; List = $false; ColumnWidths = 40, 20, 14, 13, 13 }
                        if ($Report.ShowTableCaptions) { $DomainTableParams['Caption'] = "- $($DomainTableParams.Name)" }
                        $DomainObj | Table @DomainTableParams

                        $script:ExcelSheets['Accepted Domains'] = $DomainObj
                    }
                }
            } catch {
                Write-ExoError 'TenantOverview' "Unable to retrieve Accepted Domains: $($_.Exception.Message)"
            }
            #endregion

            #region Remote Domains
            try {
                Write-Host " - Retrieving Remote Domain settings..."
                $RemoteDomains = Get-RemoteDomain -ErrorAction Stop | Sort-Object DomainName

                if ($RemoteDomains) {
                    Section -Style Heading3 'Remote Domains' {
                        Paragraph "Remote Domain settings control mail flow behaviour to external destinations from tenant $TenantId."
                        BlankLine

                        $RdObj = [System.Collections.ArrayList]::new()
                        foreach ($Rd in $RemoteDomains) {
                            $rdInObj = [ordered] @{
                                'Domain Name'            = $Rd.DomainName
                                'Auto Forward Enabled'   = $Rd.AutoForwardEnabled
                                'Allow OOF'             = $Rd.AllowedOOFType
                                'Auto Reply Enabled'     = $Rd.AutoReplyEnabled
                                'TNEF Enabled'           = $Rd.TNEFEnabled
                                'Rich Text'              = $Rd.UseSimpleDisplayName
                            }
                            $RdObj.Add([pscustomobject](ConvertTo-HashToYN $rdInObj)) | Out-Null
                        }

                        $null = (& {
                            if ($HealthCheck.ExchangeOnline.TransportRules) {
                                $null = ($RdObj | Where-Object { $_.'Auto Forward Enabled' -eq 'Yes' } | Set-Style -Style Critical | Out-Null)
                            }
                        })

                        $RdTableParams = @{ Name = "Remote Domains - $TenantId"; List = $false; ColumnWidths = 28, 15, 14, 15, 14, 14 }
                        if ($Report.ShowTableCaptions) { $RdTableParams['Caption'] = "- $($RdTableParams.Name)" }
                        $RdObj | Table @RdTableParams

                        $script:ExcelSheets['Remote Domains'] = $RdObj
                    }
                }
            } catch {
                Write-ExoError 'TenantOverview' "Unable to retrieve Remote Domains: $($_.Exception.Message)"
            }
            #endregion
        }
    }

    end {
        Show-AbrDebugExecutionTime -End -TitleMessage 'TenantOverview'
    }
}