SHELL/6.5.2.ps1

$CheckId = "6.5.2"
$Title = "Ensure MailTips are enabled for end users"
$Level = "L1"
$BenchmarkType = "Automated"

try {
    $OrgConfig = Get-OrganizationConfig -ErrorAction Stop

    $AllTipsEnabled = [bool]$OrgConfig.MailTipsAllTipsEnabled
    $ExternalTipsEnabled = [bool]$OrgConfig.MailTipsExternalRecipientsTipsEnabled
    $GroupMetricsEnabled = [bool]$OrgConfig.MailTipsGroupMetricsEnabled

    $ThresholdRaw = $OrgConfig.MailTipsLargeAudienceThreshold
    $ThresholdValue = $null
    [void][int]::TryParse([string]$ThresholdRaw, [ref]$ThresholdValue)
    $ThresholdValid = ($null -ne $ThresholdValue) -and ($ThresholdValue -gt 0)

    $Pass = $AllTipsEnabled -and $ExternalTipsEnabled -and $GroupMetricsEnabled -and $ThresholdValid
    $Status = if ($Pass) { "PASS" } else { "FAIL" }

    [pscustomobject]@{
        CheckId = $CheckId
        Title = $Title
        Level = $Level
        BenchmarkType = $BenchmarkType
        Status = $Status
        Pass = $Pass
        Evidence = [pscustomobject]@{
            MailTipsAllTipsEnabled = $AllTipsEnabled
            MailTipsExternalRecipientsTipsEnabled = $ExternalTipsEnabled
            MailTipsGroupMetricsEnabled = $GroupMetricsEnabled
            MailTipsLargeAudienceThreshold = $ThresholdRaw
            ThresholdValid = $ThresholdValid
            SourceDocument = "CIS_Microsoft_365_Foundations_Benchmark_v6.0.1"
        }
        Error = if ($Pass) { $null } else { "MailTips required settings are not fully enabled or threshold is invalid." }
        Timestamp = Get-Date
    }
}
catch {
    [pscustomobject]@{
        CheckId = $CheckId
        Title = $Title
        Level = $Level
        BenchmarkType = $BenchmarkType
        Status = "ERROR"
        Pass = $null
        Evidence = [pscustomobject]@{
            SourceDocument = "CIS_Microsoft_365_Foundations_Benchmark_v6.0.1"
        }
        Error = $_.Exception.Message
        Timestamp = Get-Date
    }
}