SHELL/6.5.5.ps1

$CheckId = "6.5.5"
$Title = "Ensure Direct Send submissions are rejected"
$Level = "L2"
$BenchmarkType = "Automated"

try {
    $OrgConfig = Get-OrganizationConfig -ErrorAction Stop
    $RejectDirectSend = [bool]$OrgConfig.RejectDirectSend

    $Pass = $RejectDirectSend
    $Status = if ($Pass) { "PASS" } else { "FAIL" }

    [pscustomobject]@{
        CheckId = $CheckId
        Title = $Title
        Level = $Level
        BenchmarkType = $BenchmarkType
        Status = $Status
        Pass = $Pass
        Evidence = [pscustomobject]@{
            RejectDirectSend = $RejectDirectSend
            SourceDocument = "CIS_Microsoft_365_Foundations_Benchmark_v6.0.1"
        }
        Error = if ($Pass) { $null } else { "RejectDirectSend is False. It must be True." }
        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
    }
}