Get-M365MfaStatus.ps1
|
<#PSScriptInfo
.VERSION 1.0.0 .GUID db7326df-0e64-5a52-bcdc-88f8f7b705e0 .AUTHOR Torsten Weise .COMPANYNAME powerscripting.de .COPYRIGHT (c) 2026 Torsten Weise. MIT-Lizenz. .TAGS Powerscripting German Microsoft365 M365 EntraID AzureAD Graph PSEdition_Desktop PSEdition_Core .LICENSEURI https://powerscripting.de/skripte/files/LICENSE.txt .PROJECTURI https://powerscripting.de/skripte/get-m365mfastatus.html .ICONURI https://powerscripting.de/assets/icon-192.png .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES Erste Veröffentlichung in der PowerShell Gallery. .PRIVATEDATA #> <# .SYNOPSIS Zeigt für jeden Benutzer im Microsoft-365-Tenant, ob MFA eingerichtet ist und mit welchen Methoden. .DESCRIPTION Liest über Microsoft Graph die registrierten Anmeldemethoden aller aktivierten Benutzer und bewertet sie: - Keine MFA: nur Kennwort. Das Konto ist mit einem einzigen geklauten Kennwort offen. - Schwach: nur SMS oder Anruf. Besser als nichts, aber per SIM-Swap und Phishing angreifbar. - Gut: Microsoft Authenticator, Software-Token (TOTP) oder ähnliches. - Stark: phishingresistent, also FIDO2-Sicherheitsschlüssel, Passkey oder Windows Hello for Business. Administratoren mit weniger als "Stark" werden zusätzlich hervorgehoben. Das Skript nutzt zuerst den Registrierungsbericht von Entra ID (schnell, ein Aufruf für alle). Fehlt dafür die Lizenz (Entra ID P1), fragt es die Methoden pro Benutzer einzeln ab. Das dauert bei großen Tenants einige Minuten, funktioniert aber auch mit Business Standard. "Eingerichtet" heißt nicht "erzwungen": Ob MFA bei der Anmeldung auch verlangt wird, regeln Sicherheitsstandards oder Richtlinien für bedingten Zugriff. Das Skript zeigt, wer vorbereitet ist. .PARAMETER IncludeGuests Gastkonten einbeziehen. Standard: nur Mitglieder. .PARAMETER IncludeUnlicensed Auch Konten ohne Lizenz einbeziehen (z. B. Dienstkonten, freigegebene Postfächer mit Anmeldung). .PARAMETER ReportPath Ordner für HTML- und CSV-Bericht. Standard: aktueller Ordner. .EXAMPLE .\Get-M365MfaStatus.ps1 Meldet sich interaktiv an und erstellt den Bericht für alle lizenzierten Mitglieder. .EXAMPLE .\Get-M365MfaStatus.ps1 -IncludeUnlicensed | Where-Object Bewertung -eq 'Keine MFA' Gibt nur die Konten ohne MFA als Objekte aus. .NOTES Autor: Torsten Weise, powerscripting.de Benötigt: Install-Module Microsoft.Graph -Scope CurrentUser Berechtigungen (Zustimmung durch einen Administrator beim ersten Start): User.Read.All, UserAuthenticationMethod.Read.All, AuditLog.Read.All Das Skript liest nur und ändert nichts im Tenant. #> #Requires -Modules Microsoft.Graph.Authentication, Microsoft.Graph.Identity.DirectoryManagement, Microsoft.Graph.Identity.SignIns, Microsoft.Graph.Reports, Microsoft.Graph.Users [CmdletBinding()] param( [switch] $IncludeGuests, [switch] $IncludeUnlicensed, [string] $ReportPath = (Get-Location).Path ) Connect-MgGraph -Scopes 'User.Read.All', 'UserAuthenticationMethod.Read.All', 'AuditLog.Read.All' -NoWelcome -ErrorAction Stop $strong = 'fido2', 'passKeyDeviceBound', 'passKeyDeviceBoundAuthenticator', 'passKeyDeviceBoundWindowsHello', 'windowsHelloForBusiness', 'platformCredential' $good = 'microsoftAuthenticatorPush', 'microsoftAuthenticatorPasswordless', 'softwareOneTimePasscode', 'hardwareOneTimePasscode', 'microsoftAuthenticator', 'temporaryAccessPass' $weak = 'mobilePhone', 'alternateMobilePhone', 'officePhone', 'sms', 'voiceMobile', 'voiceAlternateMobile', 'voiceOffice', 'phone' $names = @{ fido2 = 'FIDO2-Schlüssel'; windowsHelloForBusiness = 'Windows Hello'; platformCredential = 'Plattform-SSO (macOS)'; passKeyDeviceBound = 'Passkey' passKeyDeviceBoundAuthenticator = 'Passkey (Authenticator)'; passKeyDeviceBoundWindowsHello = 'Passkey (Windows Hello)' microsoftAuthenticatorPush = 'Authenticator'; microsoftAuthenticatorPasswordless = 'Authenticator (ohne Kennwort)' microsoftAuthenticator = 'Authenticator'; softwareOneTimePasscode = 'TOTP-App'; hardwareOneTimePasscode = 'Hardware-Token' temporaryAccessPass = 'Befristeter Zugriffspass'; mobilePhone = 'SMS/Anruf'; phone = 'SMS/Anruf'; sms = 'SMS' alternateMobilePhone = 'Anruf (Zweitnummer)'; officePhone = 'Anruf (Büro)'; email = 'E-Mail (nur SSPR)' } # Benutzer laden und filtern $users = Get-MgUser -All -Property Id, DisplayName, UserPrincipalName, AccountEnabled, UserType, AssignedLicenses | Where-Object { $_.AccountEnabled } | Where-Object { $IncludeGuests -or $_.UserType -eq 'Member' } | Where-Object { $IncludeUnlicensed -or $_.AssignedLicenses.Count -gt 0 } Write-Host "$(@($users).Count) Benutzer werden geprüft" # Methoden pro Benutzer: erst Registrierungsbericht (Entra ID P1), sonst einzeln $methods = @{} $admins = @{} try { foreach ($r in (Get-MgReportAuthenticationMethodUserRegistrationDetail -All -ErrorAction Stop)) { $methods[$r.Id] = @($r.MethodsRegistered) $admins[$r.Id] = [bool]$r.IsAdmin } Write-Host 'Quelle: Registrierungsbericht von Entra ID' } catch { Write-Host 'Registrierungsbericht nicht verfügbar (meist fehlt Entra ID P1), frage pro Benutzer ab ...' -ForegroundColor Yellow $i = 0 foreach ($u in $users) { $i++ Write-Progress -Activity 'Anmeldemethoden' -Status $u.UserPrincipalName -PercentComplete (100 * $i / @($users).Count) $list = foreach ($m in (Get-MgUserAuthenticationMethod -UserId $u.Id)) { $type = ($m.AdditionalProperties['@odata.type'] -replace '#microsoft.graph.', '') -replace 'AuthenticationMethod$', '' switch ($type) { 'password' { } 'phone' { 'mobilePhone' } 'microsoftAuthenticator' { 'microsoftAuthenticatorPush' } 'softwareOath' { 'softwareOneTimePasscode' } 'passwordlessMicrosoftAuthenticator' { 'microsoftAuthenticatorPasswordless' } default { $type } } } $methods[$u.Id] = @($list) } Write-Progress -Activity 'Anmeldemethoden' -Completed # Admins über die aktiven Verzeichnisrollen ermitteln foreach ($role in (Get-MgDirectoryRole -All)) { foreach ($m in (Get-MgDirectoryRoleMember -DirectoryRoleId $role.Id -All)) { $admins[$m.Id] = $true } } } $rows = foreach ($u in $users) { $m = @($methods[$u.Id]) $rating = if ($m | Where-Object { $_ -in $strong }) { 'Stark' } elseif ($m | Where-Object { $_ -in $good }) { 'Gut' } elseif ($m | Where-Object { $_ -in $weak }) { 'Schwach' } else { 'Keine MFA' } $isAdmin = [bool]$admins[$u.Id] [pscustomobject]@{ Name = $u.DisplayName Anmeldename = $u.UserPrincipalName Admin = if ($isAdmin) { 'Ja' } else { '' } Bewertung = $rating Methoden = (($m | Where-Object { $_ -ne 'email' } | ForEach-Object { if ($names[$_]) { $names[$_] } else { $_ } }) | Select-Object -Unique) -join ', ' Hinweis = if ($isAdmin -and $rating -ne 'Stark') { 'Admin ohne phishingresistente Methode' } else { '' } } } $order = @{ 'Keine MFA' = 0; 'Schwach' = 1; 'Gut' = 2; 'Stark' = 3 } $sorted = @($rows | Sort-Object @{ e = { $_.Admin -ne 'Ja' } }, @{ e = { $order[$_.Bewertung] } }, Name) $sorted $stats = $sorted | Group-Object Bewertung | ForEach-Object { "$($_.Name): $($_.Count)" } Write-Host ($stats -join ' | ') $now = Get-Date $tenant = (Get-MgContext).TenantId $title = "MFA-Status - $($now.ToString('dd.MM.yyyy'))" $css = '<style>body{font-family:Segoe UI,Arial,sans-serif;font-size:13px}table{border-collapse:collapse}td,th{border:1px solid #ccc;padding:4px 8px}th{background:#eee}</style>' $html = $sorted | ConvertTo-Html -Title $title -Head $css -PreContent "<h2>$title</h2><p>Tenant $tenant, $($sorted.Count) Benutzer. $($stats -join ', ').</p>" | Out-String $html = $html -replace '<td>Keine MFA</td>', '<td style="background:#f8d7da">Keine MFA</td>' ` -replace '<td>Schwach</td>', '<td style="background:#fff3cd">Schwach</td>' ` -replace '<td>Stark</td>', '<td style="background:#d4edda">Stark</td>' $base = Join-Path $ReportPath ("MFA-Status_{0:yyyy-MM-dd}" -f $now) $html | Set-Content -Path "$base.html" -Encoding UTF8 $sorted | Export-Csv -Path "$base.csv" -NoTypeInformation -Delimiter ';' -Encoding UTF8 Write-Host "Bericht: $base.html und $base.csv" |