From b46905b2213ca4d1ef55992b3591341c76e4ba08 Mon Sep 17 00:00:00 2001 From: Michael Barmettler <99532854+mibarm@users.noreply.github.com> Date: Fri, 5 Jan 2024 15:11:33 +0100 Subject: [PATCH 1/2] handle empty values in get-targetresource --- .../MSFT_EXOHostedContentFilterPolicy.psm1 | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOHostedContentFilterPolicy/MSFT_EXOHostedContentFilterPolicy.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOHostedContentFilterPolicy/MSFT_EXOHostedContentFilterPolicy.psm1 index b8f446d38f..7c98904f0a 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_EXOHostedContentFilterPolicy/MSFT_EXOHostedContentFilterPolicy.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_EXOHostedContentFilterPolicy/MSFT_EXOHostedContentFilterPolicy.psm1 @@ -312,16 +312,33 @@ function Get-TargetResource } else { - $AllowedSendersValues = $HostedContentFilterPolicy.AllowedSenders.Sender | Select-Object Address -ExpandProperty Address - $BlockedSendersValues = $HostedContentFilterPolicy.BlockedSenders.Sender | Select-Object Address -ExpandProperty Address + [System.String[]]$AllowedSendersValues = $HostedContentFilterPolicy.AllowedSenders.Sender | Select-Object Address -ExpandProperty Address + [System.String[]]$BlockedSendersValues = $HostedContentFilterPolicy.BlockedSenders.Sender | Select-Object Address -ExpandProperty Address + # Check if the values are null and assign them an empty string array if they are + if ($null -eq $AllowedSendersValues) { + $AllowedSendersValues = @() + } + if ($null -eq $BlockedSendersValues) { + $BlockedSendersValues = @() + } + + [System.String[]]$AllowedSenderDomains = $HostedContentFilterPolicy.AllowedSenderDomains.Domain + [System.String[]]$BlockedSenderDomains = $HostedContentFilterPolicy.BlockedSenderDomains.Domain + # Check if the values are null and assign them an empty string array if they are + if ($null -eq $AllowedSenderDomains) { + $AllowedSenderDomains = @() + } + if ($null -eq $BlockedSenderDomains) { + $BlockedSenderDomains = @() + } $result = @{ Ensure = 'Present' Identity = $Identity AddXHeaderValue = $HostedContentFilterPolicy.AddXHeaderValue AdminDisplayName = $HostedContentFilterPolicy.AdminDisplayName - AllowedSenderDomains = $HostedContentFilterPolicy.AllowedSenderDomains.Domain + AllowedSenderDomains = $AllowedSenderDomains AllowedSenders = $AllowedSendersValues - BlockedSenderDomains = $HostedContentFilterPolicy.BlockedSenderDomains.Domain + BlockedSenderDomains = $BlockedSenderDomains BlockedSenders = $BlockedSendersValues BulkQuarantineTag = $HostedContentFilterPolicy.BulkQuarantineTag BulkSpamAction = $HostedContentFilterPolicy.BulkSpamAction @@ -1039,26 +1056,6 @@ function Test-TargetResource $ValuesToCheck.Remove('CertificatePassword') | Out-Null $ValuesToCheck.Remove('ManagedIdentity') | Out-Null - if ($null -ne $ValuesToCheck.AllowedSenders -and $ValuesToCheck.AllowedSenders.Length -eq 0) - { - $ValuesToCheck.AllowedSenders = $null - } - - if ($null -ne $ValuesToCheck.AllowedSenderDomains -and $ValuesToCheck.AllowedSenderDomains.Length -eq 0) - { - $ValuesToCheck.AllowedSenderDomains = $null - } - - if ($null -ne $ValuesToCheck.BlockedSenders -and $ValuesToCheck.BlockedSenders.Length -eq 0) - { - $ValuesToCheck.BlockedSenders = $null - } - - if ($null -ne $ValuesToCheck.BlockedSenderDomains -and $ValuesToCheck.BlockedSenderDomains.Length -eq 0) - { - $ValuesToCheck.BlockedSenderDomains = $null - } - $TestResult = Test-M365DSCParameterState -CurrentValues $CurrentValues ` -Source $($MyInvocation.MyCommand.Source) ` -DesiredValues $ValuesToCheck ` From 6882c8e5bfa26e442191a5e5f4a8c58d0c7d333b Mon Sep 17 00:00:00 2001 From: Michael Barmettler <99532854+mibarm@users.noreply.github.com> Date: Mon, 8 Jan 2024 07:57:04 +0100 Subject: [PATCH 2/2] Add Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bed56fca1a..9755d8bce3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ # Unreleased +* EXOHostedContentFilterPolicy + * Fix issue on parameters AllowedSenders, AllowedSenderDomains, BlockedSenders, BlockSenderDomains if desired state is empty but current state is not empty + FIXES[#4124](https://github.com/microsoft/Microsoft365DSC/issues/4124) + # 1.24.103.1 * AADConditionalAccessPolicy