Skip to content

Commit 5cb0e75

Browse files
committed
Fix MFA admin alert, update mfa users alert
1 parent 2187073 commit 5cb0e75

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertMFAAdmins.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Get-CIPPAlertMFAAdmins {
2323

2424
# Check 1: Admins with no MFA registered — prefer cache, fall back to live Graph
2525
$Users = if ($MFAReport) {
26-
$MFAReport | Where-Object { $_.IsAdmin -eq $true -and $_.MFARegistration -eq $false -and ($IncludeDisabled -or $_.AccountEnabled -eq $true) }
26+
$MFAReport | Where-Object { $_.IsAdmin -eq $true -and $_.MFARegistration -eq $false -and $_.UserType -ne 'Guest' -and ($IncludeDisabled -or $_.AccountEnabled -eq $true) }
2727
} else {
2828
New-GraphGETRequest -uri "https://graph.microsoft.com/beta/reports/authenticationMethods/userRegistrationDetails?`$top=999&filter=IsAdmin eq true and isMfaRegistered eq false and userType eq 'member'&`$select=id,userDisplayName,userPrincipalName,lastUpdatedDateTime,isMfaRegistered,IsAdmin" -tenantid $($TenantFilter) -AsApp $true |
2929
Where-Object { $_.userDisplayName -ne 'On-Premises Directory Synchronization Service Account' } |
@@ -35,6 +35,7 @@ function Get-CIPPAlertMFAAdmins {
3535
$UnenforcedAdmins = $MFAReport | Where-Object {
3636
$_.IsAdmin -eq $true -and
3737
$_.MFARegistration -eq $true -and
38+
$_.UserType -ne 'Guest' -and
3839
($IncludeDisabled -or $_.AccountEnabled -eq $true) -and
3940
$_.PerUser -notin @('Enforced', 'Enabled') -and
4041
$null -ne $_.CoveredBySD -and

Modules/CIPPCore/Public/Alerts/Get-CIPPAlertMFAAlertUsers.ps1

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@ function Get-CIPPAlertMFAAlertUsers {
1111
$TenantFilter
1212
)
1313
try {
14+
$MFAReport = try { Get-CIPPMFAStateReport -TenantFilter $TenantFilter | Where-Object { $_.DisplayName -ne 'On-Premises Directory Synchronization Service Account' } } catch { $null }
15+
16+
$Users = if ($MFAReport) {
17+
$MFAReport | Where-Object { $_.IsAdmin -ne $true -and $_.MFARegistration -eq $false -and $_.UserType -ne 'Guest' -and $_.UPN -notmatch '^package_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}@' }
18+
} else {
19+
New-GraphGETRequest -uri "https://graph.microsoft.com/beta/reports/authenticationMethods/userRegistrationDetails?`$top=999&filter=IsAdmin eq false and isMfaRegistered eq false and userType eq 'member'&`$select=userDisplayName,userPrincipalName,lastUpdatedDateTime,isMfaRegistered,IsAdmin" -tenantid $($TenantFilter) -AsApp $true |
20+
Where-Object { $_.userDisplayName -ne 'On-Premises Directory Synchronization Service Account' -and $_.userPrincipalName -notmatch '^package_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}@' } |
21+
Select-Object @{n = 'UPN'; e = { $_.userPrincipalName } }, @{n = 'DisplayName'; e = { $_.userDisplayName } }
22+
}
1423

15-
$Users = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/reports/authenticationMethods/userRegistrationDetails?`$top=999&filter=IsAdmin eq false and isMfaRegistered eq false and userType eq 'member'&`$select=userDisplayName,userPrincipalName,lastUpdatedDateTime,isMfaRegistered,IsAdmin" -tenantid $($TenantFilter) -AsApp $true |
16-
Where-Object { $_.userDisplayName -ne 'On-Premises Directory Synchronization Service Account' -and $_.userPrincipalName -notmatch '^package_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}@' }
1724
if ($Users) {
1825
$AlertData = foreach ($user in $Users) {
1926
[PSCustomObject]@{
20-
UserPrincipalName = $user.userPrincipalName
21-
DisplayName = $user.userDisplayName
22-
LastUpdated = $user.lastUpdatedDateTime
27+
UserPrincipalName = $user.UPN
28+
DisplayName = $user.DisplayName
2329
}
2430
}
2531
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
26-
2732
}
2833

2934
} catch {

0 commit comments

Comments
 (0)