Skip to content

Commit ee73caa

Browse files
committed
fix: Enhance Invoke-ExecIncidentsList to improve incident filtering and error handling
1 parent 994098c commit ee73caa

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Security/Invoke-ExecIncidentsList.ps1

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function Invoke-ExecIncidentsList {
1010
# Interact with query parameters or the body of the request.
1111
$TenantFilter = $Request.Query.tenantFilter
1212
$StartDate = $Request.Query.StartDate # YYYYMMDD or null
13-
$EndDate = $Request.Query.EndDate # YYYYMMDD or null
13+
$EndDate = $Request.Query.EndDate # YYYYMMDD or null
1414

1515
# Build OData $filter parts for Graph API (single-tenant path)
1616
$GraphFilterParts = [System.Collections.Generic.List[string]]::new()
@@ -88,11 +88,18 @@ function Invoke-ExecIncidentsList {
8888
}
8989
$Incidents = $Rows
9090
foreach ($incident in $Incidents) {
91-
$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 }
91+
if ($incident.Incident -and (Test-Json -Json $incident.Incident)) {
92+
$IncidentObj = $incident.Incident | ConvertFrom-Json
93+
} else {
94+
continue
95+
}
96+
try {
97+
$created = [datetime]::Parse($IncidentObj.createdDateTime)
98+
if ($StartDate -and $created -lt [datetime]::ParseExact($StartDate, 'yyyyMMdd', $null)) { continue }
99+
if ($EndDate -and $created -ge [datetime]::ParseExact($EndDate, 'yyyyMMdd', $null).AddDays(1)) { continue }
100+
} catch {
101+
continue
102+
}
96103
[PSCustomObject]@{
97104
Tenant = $incident.Tenant
98105
Id = $IncidentObj.id

0 commit comments

Comments
 (0)