microsoft / Microsoft365DSC

Manages, configures, extracts and monitors Microsoft 365 tenant configurations
https://aka.ms/M365DSC
MIT License
1.6k stars 498 forks source link

Transport Rules ordering is tedious. Is there a better way? #3581

Closed jeremyhagan closed 1 year ago

jeremyhagan commented 1 year ago

Hi,

I'm cutting my teeth managing Transport Rules and other EXO config. Each time I create a new transport rule in the config I have to renumber everything (unless it is at the end). The only way out of this mess I can think of it to manage rule precedence outside of the DSC config. In this way new rules are always created at bottom and another script or manual process would be required to put the rule in it's correct place.

Does anyone have any more elegant ideas for this?

andikrueger commented 1 year ago

Have you tried to use the DSC DependsOn Parameter to set the sequence of execution for these resources? This might help.

jeremyhagan commented 1 year ago

Thanks for the suggestion Andi.

I'm not sure this would help. It would certainly be easier to insert a new rule in the middle of the DependsOn chain, but without specifying a Priority it would still get created with the lowest priority. Unless I am missing something.

NikCharlebois commented 1 year ago

You could, in your config, define a variable and increase its value on each rule. For example

EXOMailboxSettings 'abc'
{
   ...
}
**$i = 0**
EXOTransportRule 'RuleABC'
{
    Priority = $i++
}
EXOTransportRule 'RuleGHI'
{
    Priority = $i++
}
EXOTransportRule 'RuleDEF'
{
    Priority = $i++
}
NikCharlebois commented 1 year ago

DSC config can still use classic PowerShell logic in them and the generated value is what gets stored in the compiled file.

jeremyhagan commented 1 year ago

You could, in your config, define a variable and increase its value on each rule. For example

EXOMailboxSettings 'abc'
{
   ...
}
**$i = 0**
EXOTransportRule 'RuleABC'
{
    Priority = $i++
}
EXOTransportRule 'RuleGHI'
{
    Priority = $i++
}
EXOTransportRule 'RuleDEF'
{
    Priority = $i++
}

That's workable. Thanks Nik