Skip to content

Commit ab86520

Browse files
Merge pull request KelvinTegelaar#1698 from kris6673/issue4907-exclude-bulk-reg-mfa
Fix: Exclude bulk registration accounts from MFA alerts and improve alert structure
2 parents 5b7259f + 733ac24 commit ab86520

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@ function Get-CIPPAlertMFAAlertUsers {
44
Entrypoint
55
#>
66
[CmdletBinding()]
7-
Param (
7+
param (
88
[Parameter(Mandatory = $false)]
99
[Alias('input')]
1010
$InputValue,
1111
$TenantFilter
1212
)
1313
try {
1414

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 | Where-Object { $_.userDisplayName -ne 'On-Premises Directory Synchronization Service Account' }
16-
if ($users.UserPrincipalName) {
17-
$AlertData = "The following $($users.Count) users do not have MFA registered: $($users.UserPrincipalName -join ', ')"
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}@' }
17+
if ($Users) {
18+
$AlertData = foreach ($user in $Users) {
19+
[PSCustomObject]@{
20+
UserPrincipalName = $user.userPrincipalName
21+
DisplayName = $user.userDisplayName
22+
LastUpdated = $user.lastUpdatedDateTime
23+
}
24+
}
1825
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
1926

2027
}

0 commit comments

Comments
 (0)