Skip to content

Commit 7ff2167

Browse files
committed
handle standard alert property missing
1 parent 549ccec commit 7ff2167

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ function Push-SchedulerCIPPNotifications {
5858
$Subject = "$($Tenant): Standards are out of sync for $tenant"
5959
$HTMLContent = New-CIPPAlertTemplate -Data $Data -Format 'html' -InputObject 'standards'
6060
Send-CIPPAlert -Type 'email' -Title $Subject -HTMLContent $HTMLContent.htmlcontent -TenantFilter $tenant -APIName 'Alerts'
61-
$updateStandards = $CurrentStandardsLogs | ForEach-Object { $_.sentAsAlert = $true; $_ }
61+
$updateStandards = $CurrentStandardsLogs | ForEach-Object {
62+
if ($_.PSObject.Properties.Name -contains 'sentAsAlert') {
63+
$_.sentAsAlert = $true
64+
} else {
65+
$_ | Add-Member -MemberType NoteProperty -Name sentAsAlert -Value $true -Force
66+
}
67+
$_
68+
}
6269
if ($updateStandards) { Add-CIPPAzDataTableEntity @StandardsTable -Entity $updateStandards -Force }
6370
}
6471
}
@@ -83,8 +90,14 @@ function Push-SchedulerCIPPNotifications {
8390
$JSONContent = New-CIPPAlertTemplate -Data $Data -Format 'json' -InputObject 'table'
8491
$CurrentStandardsLogs | ConvertTo-Json -Compress
8592
Send-CIPPAlert -Type 'webhook' -JSONContent $JSONContent -TenantFilter $Tenant -APIName 'Alerts'
86-
$updateStandards = $CurrentStandardsLogs | ForEach-Object { $_.sentAsAlert = $true; $_ }
87-
if ($updateStandards) { Add-CIPPAzDataTableEntity @StandardsTable -Entity $updateStandards -Force }
93+
$updateStandards = $CurrentStandardsLogs | ForEach-Object {
94+
if ($_.PSObject.Properties.Name -contains 'sentAsAlert') {
95+
$_.sentAsAlert = $true
96+
} else {
97+
$_ | Add-Member -MemberType NoteProperty -Name sentAsAlert -Value $true -Force
98+
}
99+
$_
100+
}
88101
}
89102

90103
}
@@ -108,8 +121,14 @@ function Push-SchedulerCIPPNotifications {
108121
$Subject = "$($standardsTenant): Standards are out of sync for $standardsTenant"
109122
$HTMLContent = New-CIPPAlertTemplate -Data $Data -Format 'html' -InputObject 'standards'
110123
Send-CIPPAlert -Type 'psa' -Title $Subject -HTMLContent $HTMLContent.htmlcontent -TenantFilter $standardsTenant -APIName 'Alerts'
111-
$updateStandards = $CurrentStandardsLogs | ForEach-Object { $_.sentAsAlert = $true; $_ }
112-
if ($updateStandards) { Add-CIPPAzDataTableEntity @StandardsTable -Entity $updateStandards -Force }
124+
$updateStandards = $CurrentStandardsLogs | ForEach-Object {
125+
if ($_.PSObject.Properties.Name -contains 'sentAsAlert') {
126+
$_.sentAsAlert = $true
127+
} else {
128+
$_ | Add-Member -MemberType NoteProperty -Name sentAsAlert -Value $true -Force
129+
}
130+
$_
131+
}
113132
}
114133
} catch {
115134
Write-Information "Could not send alerts to ticketing system: $($_.Exception.message)"

0 commit comments

Comments
 (0)