Skip to content

Commit

Permalink
Merge pull request #4947 from ricmestre/fixexohostedcontentfilterrule
Browse files Browse the repository at this point in the history
EXOHostedContentFilterRule: Don't check if associated policy is present while removing resource
  • Loading branch information
NikCharlebois authored Aug 7, 2024
2 parents 7c2cb99 + e6dc717 commit 7e1cabf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log for Microsoft365DSC

# UNRELEASED

* EXOHostedContentFilterRule
* Don't check if associated `EXOHostedContentFilterPolicy` is present
while removing resource since it's not required

# 1.24.731.1

* AADAuthenticationMethodPolicyFido2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,26 +297,26 @@ function Set-TargetResource
$ConnectionMode = New-M365DSCConnection -Workload 'ExchangeOnline' `
-InboundParameters $PSBoundParameters

# Make sure that the associated Policy exists;
$AssociatedPolicy = Get-HostedContentFilterPolicy -Identity $HostedContentFilterPolicy -ErrorAction 'SilentlyContinue'
if ($null -eq $AssociatedPolicy)
{
throw "Error attempting to create EXOHostedContentFilterRule {$Identity}. The specified HostedContentFilterPolicy " + `
"{$HostedContentFilterPolicy} doesn't exist. Make sure you either create it first or specify a valid policy."
}

# Make sure that the associated Policy is not Default;
if ($AssociatedPolicy.IsDefault -eq $true )
{
throw "Policy $Identity is marked as the default. Creating a rule to apply the default policy is not allowed."
}

$CurrentValues = Get-TargetResource @PSBoundParameters
$BoundParameters = ([System.Collections.Hashtable]$PSBoundParameters).Clone()
$BoundParameters = Remove-M365DSCAuthenticationParameter -BoundParameters $PSBoundParameters

if ($Ensure -eq 'Present' -and $CurrentValues.Ensure -eq 'Absent')
{
# Make sure that the associated Policy exists;
$AssociatedPolicy = Get-HostedContentFilterPolicy -Identity $HostedContentFilterPolicy -ErrorAction 'SilentlyContinue'
if ($null -eq $AssociatedPolicy)
{
throw "Error attempting to create EXOHostedContentFilterRule {$Identity}. The specified HostedContentFilterPolicy " + `
"{$HostedContentFilterPolicy} doesn't exist. Make sure you either create it first or specify a valid policy."
}

# Make sure that the associated Policy is not Default;
if ($AssociatedPolicy.IsDefault -eq $true )
{
throw "Policy $Identity is marked as the default. Creating a rule to apply the default policy is not allowed."
}

if ($Enabled -and ('Disabled' -eq $CurrentValues.State))
{
# New-HostedContentFilterRule has the Enabled parameter, Set-HostedContentFilterRule does not.
Expand All @@ -332,6 +332,20 @@ function Set-TargetResource
}
elseif ($Ensure -eq 'Present' -and $CurrentValues.Ensure -eq 'Present')
{
# Make sure that the associated Policy exists;
$AssociatedPolicy = Get-HostedContentFilterPolicy -Identity $HostedContentFilterPolicy -ErrorAction 'SilentlyContinue'
if ($null -eq $AssociatedPolicy)
{
throw "Error attempting to create EXOHostedContentFilterRule {$Identity}. The specified HostedContentFilterPolicy " + `
"{$HostedContentFilterPolicy} doesn't exist. Make sure you either create it first or specify a valid policy."
}

# Make sure that the associated Policy is not Default;
if ($AssociatedPolicy.IsDefault -eq $true )
{
throw "Policy $Identity is marked as the default. Creating a rule to apply the default policy is not allowed."
}

$BoundParameters.Remove('Enabled') | Out-Null
if ($CurrentValues.HostedContentFilterPolicy -eq $BoundParameters.HostedContentFilterPolicy)
{
Expand Down

0 comments on commit 7e1cabf

Please sign in to comment.