Skip to content

Commit

Permalink
Merge pull request #5485 from NikCharlebois/EXOTransportRule-fixes
Browse files Browse the repository at this point in the history
EXOTransportRule - Fixed Creation and Update Logic
  • Loading branch information
NikCharlebois authored Nov 29, 2024
2 parents 6fca37b + a3ce220 commit 8223040
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
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

0 comments on commit 8223040

Please sign in to comment.