@@ -27,17 +27,16 @@ function Invoke-CIPPStandardTransportRuleTemplate {
2727 #>
2828 param ($Tenant , $Settings )
2929 # #$Rerun -Type Standard -Tenant $Tenant -Settings $Settings 'TransportRuleTemplate'
30-
31- If ($Settings.remediate -eq $true ) {
30+ $existingRules = New-ExoRequest - ErrorAction SilentlyContinue - tenantid $Tenant - cmdlet ' Get-TransportRule ' - useSystemMailbox $true
31+ if ($Settings.remediate -eq $true ) {
3232 Write-Host " Settings: $ ( $Settings | ConvertTo-Json ) "
3333 $Settings.transportRuleTemplate ? ($Settings | Add-Member - NotePropertyName ' TemplateList' - NotePropertyValue $Settings.transportRuleTemplate ) : $null
3434 foreach ($Template in $Settings.TemplateList ) {
3535 Write-Host " working on $ ( $Template.value ) "
3636 $Table = Get-CippTable - tablename ' templates'
3737 $Filter = " PartitionKey eq 'TransportTemplate' and RowKey eq '$ ( $Template.value ) '"
3838 $RequestParams = (Get-AzDataTableEntity @Table - Filter $Filter ).JSON | ConvertFrom-Json
39- $Existing = New-ExoRequest - ErrorAction SilentlyContinue - tenantid $Tenant - cmdlet ' Get-TransportRule' - useSystemMailbox $true | Where-Object - Property Identity -EQ $RequestParams.name
40-
39+ $Existing = $existingRules | Where-Object - Property Identity -EQ $RequestParams.name
4140
4241 try {
4342 if ($Existing ) {
@@ -58,4 +57,21 @@ function Invoke-CIPPStandardTransportRuleTemplate {
5857 }
5958 }
6059 }
60+ if ($Settings.report -eq $true ) {
61+ $rules = $Settings.transportRuleTemplate.JSON | ConvertFrom-Json - Depth 10
62+ $MissingRules = foreach ($rule in $rules ) {
63+ $CheckExististing = $existingRules | Where-Object - Property identity -EQ $rule.displayname
64+ if (! $CheckExististing ) {
65+ $rule.displayname
66+ }
67+ }
68+
69+ if ($MissingRules.Count -eq 0 ) {
70+ $fieldValue = $true
71+ } else {
72+ $fieldValue = $MissingRules -join ' , '
73+ }
74+
75+ Set-CIPPStandardsCompareField - FieldName ' standards.TransportRuleTemplate' - FieldValue $fieldValue - Tenant $Tenant
76+ }
6177}
0 commit comments