SHELL/7.2.1.ps1

$CheckId = "7.2.1"
$Title = "Ensure modern authentication for SharePoint applications is required"
$Level = "L1"
$BenchmarkType = "Automated"

try {
    $TenantSettings = Get-SPOTenant
    $LegacyAuthProtocolsEnabled = $TenantSettings.LegacyAuthProtocolsEnabled

    if ($null -eq $LegacyAuthProtocolsEnabled) {
        [pscustomobject]@{
            CheckId   = $CheckId
            Title     = $Title
            Level     = $Level
            Status    = "MANUAL_REVIEW"
            Pass      = $null
            Evidence  = [pscustomobject]@{
                LegacyAuthProtocolsEnabled = $null
                ReviewAction               = "Verify LegacyAuthProtocolsEnabled is set to False."
            }
            Error     = "LegacyAuthProtocolsEnabled was not returned by Get-SPOTenant."
            Timestamp = Get-Date
        }
    }
    else {
        $LegacyEnabled = [bool]$LegacyAuthProtocolsEnabled
        $Pass = -not $LegacyEnabled

        [pscustomobject]@{
            CheckId   = $CheckId
            Title     = $Title
            Level     = $Level
            Status    = if ($Pass) { "PASS" } else { "FAIL" }
            Pass      = $Pass
            Evidence  = [pscustomobject]@{
                LegacyAuthProtocolsEnabled = $LegacyEnabled
                RecommendedState           = "False"
            }
            Error     = $null
            Timestamp = Get-Date
        }
    }
}
catch {
    [pscustomobject]@{
        CheckId   = $CheckId
        Title     = $Title
        Level     = $Level
        Status    = "ERROR"
        Pass      = $null
        Evidence  = $null
        Error     = $_.Exception.Message
        Timestamp = Get-Date
    }
}