Last active
May 13, 2025 17:53
-
-
Save nathanmcnulty/d90be50f6260ed78874f8b5576a13f2c to your computer and use it in GitHub Desktop.
Graph API Reports for CA Blocked Sign-Ins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Graph PowerShell: | |
| (Invoke-MgGraphRequest -Uri "/beta/reports/serviceActivity/getMetricsForConditionalAccessBlockedSignIn(inclusiveIntervalStartDateTime=$((Get-Date).AddMinutes(-5).ToString("yyyy-MM-ddTHH:mm:ssZ")),exclusiveIntervalEndDateTime=$((Get-Date).ToString("yyyy-MM-ddTHH:mm:ssZ")),aggregationIntervalInMinutes=5)").value | |
| Logic App: | |
| { | |
| "definition": { | |
| "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", | |
| "contentVersion": "1.0.0.0", | |
| "triggers": { | |
| "Every_5_minutes": { | |
| "recurrence": { | |
| "interval": 5, | |
| "frequency": "Minute" | |
| }, | |
| "evaluatedRecurrence": { | |
| "interval": 5, | |
| "frequency": "Minute" | |
| }, | |
| "type": "Recurrence" | |
| } | |
| }, | |
| "actions": { | |
| "Get_CA_Blocked_Sign_Ins_Report": { | |
| "runAfter": {}, | |
| "type": "Http", | |
| "inputs": { | |
| "uri": "https://graph.microsoft.com/beta/reports/serviceActivity/getMetricsForConditionalAccessBlockedSignIn(inclusiveIntervalStartDateTime=@{formatDateTime(addMinutes(utcNow(),-5),'yyyy-MM-ddTHH:mm:ssZ')},exclusiveIntervalEndDateTime=@{formatDateTime(utcNow(),'yyyy-MM-ddTHH:mm:ssZ')},aggregationIntervalInMinutes=5)", | |
| "method": "GET", | |
| "authentication": { | |
| "type": "ManagedServiceIdentity", | |
| "audience": "https://graph.microsoft.com" | |
| } | |
| }, | |
| "runtimeConfiguration": { | |
| "contentTransfer": { | |
| "transferMode": "Chunked" | |
| } | |
| } | |
| }, | |
| "ForEach_Value": { | |
| "foreach": "@body('Get_CA_Blocked_Sign_Ins_Report')['value']", | |
| "actions": { | |
| "True_if_greater_than_5": { | |
| "actions": {}, | |
| "else": { | |
| "actions": {} | |
| }, | |
| "expression": { | |
| "and": [ | |
| { | |
| "greater": [ | |
| "@items('ForEach_Value')['value']", | |
| 5 | |
| ] | |
| } | |
| ] | |
| }, | |
| "type": "If" | |
| } | |
| }, | |
| "runAfter": { | |
| "Get_CA_Blocked_Sign_Ins_Report": [ | |
| "Succeeded" | |
| ] | |
| }, | |
| "type": "Foreach" | |
| } | |
| }, | |
| "outputs": {}, | |
| "parameters": { | |
| "$connections": { | |
| "type": "Object", | |
| "defaultValue": {} | |
| } | |
| } | |
| }, | |
| "parameters": { | |
| "$connections": { | |
| "type": "Object", | |
| "value": {} | |
| } | |
| } | |
| } | |
| Permissions for Managed Identity: | |
| $SP_ID = "<MI ObjectId>" | |
| $GraphSP = Get-MgServicePrincipal -Filter "startswith(DisplayName,'Microsoft Graph')" | Select-Object -first 1 #Graph App ID: 00000003-0000-0000-c000-000000000000 | |
| $AppRole = $GraphSP.AppRoles | Where-Object {$_.Value -eq "Reports.Read.All" -and $_.AllowedMemberTypes -contains "Application"} | |
| New-MgServicePrincipalAppRoleAssignment -AppRoleId $AppRole.Id -ServicePrincipalId $SP_ID -ResourceId $GraphSP.Id -PrincipalId $SP_ID |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @albert-widjaja, so sorry I missed this. I have not been able to reproduce this error. What if you try changing .AddMinutes(-5) to .AddMinutes(-10) or something. Maybe the window is just slightly too tight.