SHELL/7.2.5.ps1

$CheckId = "7.2.5"
$Title = "Ensure that SharePoint guest users cannot share items they don't own"
$Level = "L2"
$BenchmarkType = "Automated"

try {
    $TenantConfig = Get-SPOTenant -ErrorAction Stop
    $PreventExternalUsersFromResharing = [bool]$TenantConfig.PreventExternalUsersFromResharing

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

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