Skip to content

Commit 41de183

Browse files
author
Luis Mengel
committed
Fix order-dependent comparison in MailContacts standard evaluation
1 parent 2bc6c54 commit 41de183

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardMailContacts.ps1

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ function Invoke-CIPPStandardMailContacts {
4444
return
4545
}
4646
$contacts = $settings
47-
$TechAndSecurityContacts = @($Contacts.SecurityContact, $Contacts.TechContact)
47+
$TechAndSecurityContacts = @(@($contacts.SecurityContact, $contacts.TechContact) | Where-Object { $_ } | Select-Object -Unique)
4848

49-
$state = $CurrentInfo.marketingNotificationEmails -eq $Contacts.MarketingContact -and `
50-
($CurrentInfo.securityComplianceNotificationMails -in $TechAndSecurityContacts -or
51-
$CurrentInfo.technicalNotificationMails -in $TechAndSecurityContacts) -and `
52-
$CurrentInfo.privacyProfile.contactEmail -eq $Contacts.GeneralContact
49+
$marketingMatch = @($CurrentInfo.marketingNotificationEmails) -contains $contacts.MarketingContact
50+
$techMatch = -not (Compare-Object @($CurrentInfo.technicalNotificationMails) $TechAndSecurityContacts)
51+
$generalMatch = $CurrentInfo.privacyProfile.contactEmail -eq $contacts.GeneralContact
52+
53+
$state = $marketingMatch -and $techMatch -and $generalMatch
5354

5455
if ($Settings.remediate -eq $true) {
5556
if ($state) {
@@ -105,13 +106,13 @@ function Invoke-CIPPStandardMailContacts {
105106
}
106107
if ($Settings.report -eq $true) {
107108
$CurrentValue = @{
108-
marketingNotificationEmails = @($CurrentInfo.marketingNotificationEmails)
109-
technicalNotificationMails = @($CurrentInfo.technicalNotificationMails)
109+
marketingNotificationEmails = @($CurrentInfo.marketingNotificationEmails | Sort-Object)
110+
technicalNotificationMails = @($CurrentInfo.technicalNotificationMails | Sort-Object)
110111
contactEmail = $CurrentInfo.privacyProfile.contactEmail
111112
}
112113
$ExpectedValue = @{
113-
marketingNotificationEmails = @($Contacts.MarketingContact)
114-
technicalNotificationMails = @(@($Contacts.SecurityContact, $Contacts.TechContact) | Where-Object { $_ -ne $null } | Select-Object -Unique)
114+
marketingNotificationEmails = @($Contacts.MarketingContact | Sort-Object)
115+
technicalNotificationMails = @(@($Contacts.SecurityContact, $Contacts.TechContact) | Where-Object { $_ -ne $null } | Select-Object -Unique | Sort-Object)
115116
contactEmail = $Contacts.GeneralContact
116117
}
117118
Set-CIPPStandardsCompareField -FieldName 'standards.MailContacts' -CurrentValue $CurrentValue -ExpectedValue $ExpectedValue -Tenant $tenant

0 commit comments

Comments
 (0)