r/PowerShell • u/quiet_tenant_admin • Sep 29 '26
Script Sharing Free read-only M365 tenant audit script: scores your tenant 0-100 and writes an HTML report
I'm the only IT person at a ~150-user company and wanted one command that checks the M365 basics I kept verifying by hand across five admin portals.
It uses Microsoft Graph with read-only scopes and makes no changes. It checks MFA / Conditional Access coverage, legacy auth, Global Admin count, stale accounts, app consent settings, expiring app secrets, Intune compliance, Secure Score, and SPF/DMARC/DKIM (via DNS-over-HTTPS, so it runs on macOS/Linux too). Each finding gets a weight and a fix, then everything rolls into a score.
How a CA policy is treated as "requires MFA":
function Test-RequiresMfa {
param($Policy)
$g = $Policy.grantControls
if (-not $g) { return $false }
return (($g.builtInControls -contains 'mfa') -or ($null -ne $g.authenticationStrength))
}How the score is calculated (Warn counts as half):
$scored = @($Results | Where-Object { $_.Status -in 'Pass', 'Warn', 'Fail' })
$max = ($scored | Measure-Object -Property Weight -Sum).Sum
$got = 0
foreach ($r in $scored) {
if ($r.Status -eq 'Pass') { $got += $r.Weight }
elseif ($r.Status -eq 'Warn') { $got += $r.Weight / 2 }
}
$score = if ($max -gt 0) { [math]::Round(($got / $max) * 100) } else { 0 }Install from the Gallery:
Install-Script -Name Invoke-M365TenantAudit -Scope CurrentUserFull source (MIT): https://github.com/adminofone/m365-tenant-audit
Written with AI assistance and tested on a real tenant. Code review welcome, especially on the Graph paging and error handling.
19
u/PipeItToDevNull Sep 29 '26
Look at the CISA SCUBA tool
4
u/WearyDeluge Sep 29 '26
Or 365Inspect
3
u/daweinah Sep 29 '26
How does this compare to, or why should I use it instead of, https://maester.dev/?
2
u/uptimefordays Sep 29 '26
Love the idea here! You should implement some Pester tests and maybe think about your use of
Install-Module -Force -AllowClobberif Graph is missing which seems like an odd choice for a security tool. Also your admin-MFA check counts any "All users" policy without looking at exclusions which means a policy that excludes admins would still pass.1
u/jcpham Sep 29 '26
Nice, thanks