11param ($tenant )
2- Write-Host $ ($Tenant.tenant )
3- Write-Host $ ($Tenant.tag )
42Write-Host $ ($Tenant | ConvertTo-Json )
5- # thoughts: add more delta/tracking to prevent duplicate alerts.
63if ($Tenant.tag -eq " AllTenants" ) {
74 $Alerts = Get-Content " .\Cache_Scheduler\AllTenants.alert.json" | ConvertFrom-Json
85}
96else {
107 $Alerts = Get-Content " .\Cache_Scheduler\$ ( $tenant.tenant ) .alert.json" | ConvertFrom-Json
118}
129$ShippedAlerts = switch ($Alerts ) {
10+
1311 { $Alerts ." AdminPassword" -eq $true } {
1412 New-GraphGETRequest - uri " https://graph.microsoft.com/beta/roleManagement/directory/roleAssignments?`$ filter=roleDefinitionId eq '62e90394-69f5-4237-9190-012177145e10'" - tenantid $ ($tenant.tenant ) | ForEach-Object {
1513 $LastChanges = New-GraphGETRequest - uri " https://graph.microsoft.com/beta/users/$ ( $_.principalId ) ?`$ select=UserPrincipalName,lastPasswordChangeDateTime" - tenant $ ($tenant.tenant )
@@ -30,17 +28,17 @@ $ShippedAlerts = switch ($Alerts) {
3028 { $_ ." MFAAdmins" -eq $true } {
3129 $AdminIds = (New-GraphGETRequest - uri " https://graph.microsoft.com/beta/roleManagement/directory/roleAssignments?`$ filter=roleDefinitionId eq '62e90394-69f5-4237-9190-012177145e10'&expand=principal" - tenantid $ ($tenant.tenant )).principal
3230 $AdminList = Get-CIPPMSolUsers - tenant $tenant.tenant | Where-Object - Property ObjectID -In $AdminIds.id
33- $MFARegistration = (New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/reports/credentialUserRegistrationDetails' - tenantid $tenant.tenant )
31+ try { $MFARegistration = (New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/reports/credentialUserRegistrationDetails' - tenantid $tenant.tenant - ErrorAction) } catch {}
3432 $AdminList | Where-Object { $_.Usertype -eq " Member" -and $_.BlockCredential -eq $false } | ForEach-Object {
35- $CARegistered = ($MFARegistration | Where-Object - Property UserPrincipalName -EQ $_.UserPrincipalName ).IsMFARegistered
33+ $CARegistered = [ boolean ] ($MFARegistration | Where-Object - Property UserPrincipalName -EQ $_.UserPrincipalName ).IsMFARegistered
3634 if ($_.StrongAuthenticationRequirements.StrongAuthenticationRequirement.state -eq $null -and $CARegistered -eq $false ) { " Admin $ ( $_.UserPrincipalName ) is enabled but does not have any form of MFA configured." }
3735 }
3836 }
3937 { $_ ." MFAAlertUsers" -eq $true } {
4038 $users = Get-CIPPMSolUsers - tenant $tenant.tenant
41- $MFARegistration = (New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/reports/credentialUserRegistrationDetails' - tenantid $tenant.tenant )
39+ try { $MFARegistration = (New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/reports/credentialUserRegistrationDetails' - tenantid $tenant.tenant - ErrorAction) } catch {}
4240 $users | Where-Object { $_.Usertype -eq " Member" -and $_.BlockCredential -eq $false } | ForEach-Object {
43- $CARegistered = ($MFARegistration | Where-Object - Property UserPrincipalName -EQ $_.UserPrincipalName ).IsMFARegistered
41+ $CARegistered = [ boolean ] ($MFARegistration | Where-Object - Property UserPrincipalName -EQ $_.UserPrincipalName ).IsMFARegistered
4442 if ($_.StrongAuthenticationRequirements.StrongAuthenticationRequirement.state -eq $null -and $CARegistered -eq $false ) { " User $ ( $_.UserPrincipalName ) is enabled but does not have any form of MFA configured." }
4543 }
4644 }
@@ -87,9 +85,13 @@ $ShippedAlerts = switch ($Alerts) {
8785 }
8886}
8987$currentlog = Get-Content " Logs\$ ( (Get-Date ).ToString(' ddMMyyyy' )) .log" | ConvertFrom-Csv - Header " DateTime" , " Tenant" , " API" , " Message" , " User" , " Severity" - Delimiter " |" | Where-Object - Property Tenant -EQ $tenant.tenant
88+ Write-Host $ShippedAlerts
9089$ShippedAlerts | ForEach-Object {
9190 if ($_ -in $currentlog.message ) {
9291 continue
9392 }
9493 Log- Request - message $_ - API " Alerts" - tenant $tenant.tenant - sev Alert
9594}
95+ [PSCustomObject ]@ {
96+ ReturnedValues = $true
97+ }
0 commit comments