Skip to content

Commit a7c767f

Browse files
committed
Add Reference field to scheduled task handling
Introduces a 'Reference' field to scheduled task entities and propagates its usage through task creation, execution, and notification logic. This allows tasks to be associated with an external or user-defined reference for improved traceability.
1 parent 1354aa6 commit a7c767f

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,21 +174,22 @@ function Add-CIPPScheduledTask {
174174
}
175175

176176
$entity = @{
177-
PartitionKey = [string]'ScheduledTask'
178-
TaskState = [string]'Planned'
179-
RowKey = [string]$RowKey
180-
Tenant = [string]$tenantFilter
181-
excludedTenants = [string]$excludedTenants
182-
Name = [string]$task.Name
183-
Command = [string]$task.Command.value
184-
Parameters = [string]$Parameters
185-
ScheduledTime = [string]$task.ScheduledTime
186-
Recurrence = [string]$Recurrence
187-
PostExecution = [string]$PostExecution
188-
AdditionalProperties = [string]$AdditionalProperties
189-
Hidden = [bool]$Hidden
190-
Results = 'Planned'
191-
AlertComment = [string]$task.AlertComment
177+
PartitionKey = [string]'ScheduledTask'
178+
TaskState = [string]'Planned'
179+
RowKey = [string]$RowKey
180+
Tenant = [string]$tenantFilter
181+
excludedTenants = [string]$excludedTenants
182+
Name = [string]$task.Name
183+
Command = [string]$task.Command.value
184+
Parameters = [string]$Parameters
185+
ScheduledTime = [string]$task.ScheduledTime
186+
Recurrence = [string]$Recurrence
187+
PostExecution = [string]$PostExecution
188+
Reference = [string]$task.Reference
189+
AdditionalProperties = [string]$AdditionalProperties
190+
Hidden = [bool]$Hidden
191+
Results = 'Planned'
192+
AlertComment = [string]$task.AlertComment
192193
}
193194

194195

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ function Push-ExecScheduledCommand {
280280
$HTML += "<div style='background-color: transparent; border-left: 4px solid #007bff; padding: 15px; margin: 15px 0;'><h4 style='margin-top: 0; color: #007bff;'>Alert Information</h4><p style='margin-bottom: 0;'>$($task.AlertComment)</p></div>"
281281
}
282282

283-
$title = "$TaskType - $Tenant - $($task.Name)"
283+
$title = "$TaskType - $Tenant - $($task.Name)$(if ($task.Reference) { " - $($task.Reference)" })"
284284
Write-Information 'Scheduler: Sending the results to the target.'
285285
Write-Information "The content of results is: $Results"
286286
switch -wildcard ($task.PostExecution) {

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-AddUser.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ function Invoke-AddUser {
2323
value = 'New-CIPPUserTask'
2424
label = 'New-CIPPUserTask'
2525
}
26-
Parameters = [pscustomobject]@{ UserObj = $UserObj }
27-
ScheduledTime = $UserObj.Scheduled.date
28-
PostExecution = @{
26+
Parameters = [pscustomobject]@{ UserObj = $UserObj }
27+
ScheduledTime = $UserObj.Scheduled.date
28+
Reference = $UserObj.reference ?? $null
29+
PostExecution = @{
2930
Webhook = [bool]$Request.Body.PostExecution.Webhook
3031
Email = [bool]$Request.Body.PostExecution.Email
3132
PSA = [bool]$Request.Body.PostExecution.PSA

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Conditional/Invoke-ExecCAExclusion.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ function Invoke-ExecCAExclusion {
8484
}
8585
Parameters = [pscustomobject]$Parameters
8686
ScheduledTime = $StartDate
87+
PostExecution = $Request.Body.postExecution
88+
Reference = $Request.Body.reference
8789
}
8890

8991
Write-Information ($TaskBody | ConvertTo-Json -Depth 10)
@@ -117,6 +119,7 @@ function Invoke-ExecCAExclusion {
117119
Command = @{ value = 'Set-CIPPAuditLogUserExclusion'; label = 'Set-CIPPAuditLogUserExclusion' }
118120
Parameters = [pscustomobject]@{ Users = $AuditUsers; Action = 'Remove'; Type = 'Location' }
119121
ScheduledTime = $EndDate
122+
Reference = $Request.Body.reference
120123
}
121124
Add-CIPPScheduledTask -Task $AuditRemoveTask -hidden $true
122125
}

0 commit comments

Comments
 (0)