SHELL/8.1.2.ps1

$CheckId = "8.1.2"
$Title = "Ensure users can't send emails to a channel email address"
$Level = "L1"
$BenchmarkType = "Automated"

try {
    $Config = Get-CsTeamsClientConfiguration -Identity Global -ErrorAction Stop
    $AllowEmailIntoChannel = [bool]$Config.AllowEmailIntoChannel

    $Pass = -not $AllowEmailIntoChannel
    $Status = if ($Pass) { "PASS" } else { "FAIL" }

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