@@ -9,11 +9,25 @@ function Invoke-ExecIncidentsList {
99 param ($Request , $TriggerMetadata )
1010 # Interact with query parameters or the body of the request.
1111 $TenantFilter = $Request.Query.tenantFilter
12+ $StartDate = $Request.Query.StartDate # YYYYMMDD or null
13+ $EndDate = $Request.Query.EndDate # YYYYMMDD or null
14+
15+ # Build OData $filter parts for Graph API (single-tenant path)
16+ $GraphFilterParts = [System.Collections.Generic.List [string ]]::new()
17+ if ($StartDate ) {
18+ $GraphFilterParts.Add (" createdDateTime ge $ ( [datetime ]::ParseExact($StartDate , ' yyyyMMdd' , $null ).ToString(' yyyy-MM-ddT00:00:00Z' )) " )
19+ }
20+ if ($EndDate ) {
21+ $GraphFilterParts.Add (" createdDateTime le $ ( [datetime ]::ParseExact($EndDate , ' yyyyMMdd' , $null ).ToString(' yyyy-MM-ddT23:59:59Z' )) " )
22+ }
23+ $GraphODataFilter = if ($GraphFilterParts.Count -gt 0 ) { ' $filter=' + ($GraphFilterParts -join ' and ' ) } else { $null }
1224
1325 try {
1426 $GraphRequest = if ($TenantFilter -ne ' AllTenants' ) {
1527 # Single tenant functionality
16- $Incidents = New-GraphGetRequest - uri ' https://graph.microsoft.com/beta/security/incidents' - tenantid $TenantFilter - AsApp $true
28+ $IncidentsUri = ' https://graph.microsoft.com/beta/security/incidents'
29+ if ($GraphODataFilter ) { $IncidentsUri = " $IncidentsUri `?$GraphODataFilter " }
30+ $Incidents = New-GraphGetRequest - uri $IncidentsUri - tenantid $TenantFilter - AsApp $true
1731
1832 foreach ($incident in $Incidents ) {
1933 [PSCustomObject ]@ {
@@ -29,7 +43,7 @@ function Invoke-ExecIncidentsList {
2943 Classification = $incident.classification
3044 Determination = $incident.determination
3145 Severity = $incident.severity
32- Tags = ($IncidentObj .tags -join ' , ' )
46+ Tags = ($incident .tags -join ' , ' )
3347 Comments = $incident.comments
3448 }
3549 }
@@ -75,6 +89,10 @@ function Invoke-ExecIncidentsList {
7589 $Incidents = $Rows
7690 foreach ($incident in $Incidents ) {
7791 $IncidentObj = $incident.Incident | ConvertFrom-Json
92+ # In-memory date filter for cached AllTenants data
93+ $created = [datetime ]::Parse($IncidentObj.createdDateTime )
94+ if ($StartDate -and $created -lt [datetime ]::ParseExact($StartDate , ' yyyyMMdd' , $null )) { continue }
95+ if ($EndDate -and $created -ge [datetime ]::ParseExact($EndDate , ' yyyyMMdd' , $null ).AddDays(1 )) { continue }
7896 [PSCustomObject ]@ {
7997 Tenant = $incident.Tenant
8098 Id = $IncidentObj.id
0 commit comments