Skip to content

Commit 6498a41

Browse files
committed
search tweaks
1 parent 625675b commit 6498a41

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Modules/CIPPCore/Public/AuditLogs/New-CippAuditLogSearch.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function New-CippAuditLogSearch {
125125
)
126126

127127
$SearchParams = @{
128-
displayName = 'CIPP Audit Search - ' + (Get-Date).ToString('yyyy-MM-dd HH:mm:ss')
128+
displayName = $DisplayName
129129
filterStartDateTime = $StartTime.ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss')
130130
filterEndDateTime = $EndTime.AddHours(1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss')
131131
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Alerts/Invoke-ExecAuditLogSearch.ps1

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ function Invoke-ExecAuditLogSearch {
2828
return
2929
}
3030

31+
# Convert StartTime and EndTime to DateTime from unixtime
32+
if ($Query.StartTime -match '^\d+$') {
33+
$Query.StartTime = [DateTime]::UnixEpoch.AddSeconds([long]$Query.StartTime)
34+
} else {
35+
$Query.StartTime = [DateTime]$Query.StartTime
36+
}
37+
38+
if ($Query.EndTime -match '^\d+$') {
39+
$Query.EndTime = [DateTime]::UnixEpoch.AddSeconds([long]$Query.EndTime)
40+
} else {
41+
$Query.EndTime = [DateTime]$Query.EndTime
42+
}
43+
3144
$Command = Get-Command New-CippAuditLogSearch
3245
$AvailableParameters = $Command.Parameters.Keys
3346
$BadProps = foreach ($Prop in $Query.PSObject.Properties.Name) {
@@ -44,8 +57,23 @@ function Invoke-ExecAuditLogSearch {
4457
}
4558

4659
try {
60+
Write-Information "Executing audit log search with parameters: $($Query | ConvertTo-Json -Depth 10)"
61+
4762
$Query = $Query | ConvertTo-Json -Depth 10 | ConvertFrom-Json -AsHashtable
48-
$Results = New-CippAuditLogSearch @Query
63+
$NewSearch = New-CippAuditLogSearch @Query
64+
65+
if ($NewSearch) {
66+
$Results = @{
67+
resultText = "Created audit log search: $($NewSearch.displayName)"
68+
state = 'success'
69+
details = $NewSearch
70+
}
71+
} else {
72+
$Results = @{
73+
resultText = 'Failed to initiate search'
74+
state = 'error'
75+
}
76+
}
4977
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
5078
StatusCode = [HttpStatusCode]::OK
5179
Body = $Results

0 commit comments

Comments
 (0)