Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXOTransportRule - Fixed Creation and Update Logic #5485

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* All resources
* Applying project default formatting on all files, to improve
reading and troubleshooting
* EXOTransportRule
* Fixed conditional logic for creation and update.
* IntuneTrustedRootCertificateIOS
* Initial release
* M365DSCDRGUtil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,20 @@ function Set-TargetResource
if ($Ensure -eq 'Present' -and $currentTransportRuleConfig.Ensure -eq 'Absent')
{
Write-Verbose -Message "Transport Rule '$($Name)' does not exist but it should. Create and configure it."

$nullKeysToRemove = @()
foreach ($key in $NewTransportRuleParams.Keys)
{
if ($NewTransportRuleParams.$key.GetType().Name -eq 'String[]' -and $NewTransportRuleParams.$key.Length -eq 0)
{
$nullKeysToRemove += $key
}
}
foreach ($paramToRemove in $nullKeysToRemove)
{
$NewTransportRuleParams.Remove($paramToRemove) | Out-Null
}

# Create Transport Rule
New-TransportRule @NewTransportRuleParams

Expand All @@ -1809,7 +1823,34 @@ function Set-TargetResource
}
# CASE: Transport Rule exists and it should, but has different values than the desired ones
elseif ($Ensure -eq 'Present' -and $currentTransportRuleConfig.Ensure -eq 'Present')
{
{
if ($null -ne $HeaderContainsMessageHeader -and $null -eq $currentTransportRuleConfig.HeaderContainsMessageHeader)
{
$SetTransportRuleParams.Add("HeaderContainsMessageHeader",$null)
}
if ($null -ne $HeaderMatchesPatterns -and $null -eq $currentTransportRuleConfig.HeaderMatchesMessageHeader)
{
$SetTransportRuleParams.Add("HeaderMatchesMessageHeader",$null)
}
if ($null -ne $ExceptIfHeaderContainsWords -and $null -eq $currentTransportRuleConfig.ExceptIfHeaderContainsMessageHeader)
{
$SetTransportRuleParams.Add("ExceptIfHeaderContainsMessageHeader",$null)
}
if ($null -ne $ExceptIfHeaderMatchesPatterns -and $null -eq $currentTransportRuleConfig.ExceptIfHeaderMatchesMessageHeader)
{
$SetTransportRuleParams.Add("ExceptIfHeaderMatchesMessageHeader",$null)
}
if ($null -ne $ApplyOME)
{
Write-Warning -Message "ApplyOME is deprecated. Use ApplyRightsProtectionTemplate instead."
$SetTransportRuleParams.Remove("ApplyOME") | Out-Null
}
if ($null -ne $RemoveOME)
{
Write-Warning -Message "RemoveOME is deprecated. Use RemoveOMEv2 instead."
$SetTransportRuleParams.Remove("RemoveOME") | Out-Null
}

Write-Verbose -Message "Transport Rule '$($Name)' already exists, but needs updating."
Write-Verbose -Message "Setting Transport Rule $($Name) with values: $(Convert-M365DscHashtableToString -Hashtable $SetTransportRuleParams)"
Set-TransportRule @SetTransportRuleParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,21 @@ function Get-TargetResource
}
catch
{
New-M365DSCLogEntry -Message 'Error retrieving data:' `
-Exception $_ `
-Source $($MyInvocation.MyCommand.Source) `
-TenantId $TenantId `
-Credential $Credential

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
if ($_.Exception.Message -eq 'Multiple Policies with same displayname identified - Module currently only functions with unique names')
{
throw $_
}
else
{
New-M365DSCLogEntry -Message 'Error retrieving data:' `
-Exception $_ `
-Source $($MyInvocation.MyCommand.Source) `
-TenantId $TenantId `
-Credential $Credential

$nullResult = Clear-M365DSCAuthenticationParameter -BoundParameters $nullResult
return $nullResult
}
}
}

Expand Down