Public/Get-MailFlowRuleExport.ps1
|
function Get-MailFlowRuleExport { <# .SYNOPSIS Exports Exchange transport (mail flow) rules for migration review. .DESCRIPTION Retrieves all transport rules and exports them in a format suitable for migration planning. Each rule is documented with its conditions, actions, and any migration concerns. .PARAMETER IncludeDisabled Include disabled rules in the export. .EXAMPLE Get-MailFlowRuleExport .EXAMPLE Get-MailFlowRuleExport -IncludeDisabled | Export-Csv MailFlowRules.csv #> [CmdletBinding()] param( [switch]$IncludeDisabled ) $rules = Get-TransportRule -ResultSize Unlimited if (-not $IncludeDisabled) { $rules = $rules | Where-Object State -eq 'Enabled' } foreach ($rule in $rules) { # Identify potential migration issues $concerns = [System.Collections.Generic.List[string]]::new() if ($rule.Conditions | Where-Object { $_ -match 'Header' }) { $concerns.Add('Uses header conditions - verify in EXO') } if ($rule.Actions | Where-Object { $_ -match 'Redirect' }) { $concerns.Add('Redirects mail - verify target exists in EXO') } if ($rule.ExceptIfSenderDomainIs -or $rule.SenderDomainIs) { $concerns.Add('Domain-based rule - verify domains post-migration') } [PSCustomObject]@{ Name = $rule.Name Priority = $rule.Priority State = $rule.State Mode = $rule.Mode SenderScope = if ($rule.FromScope) { $rule.FromScope } else { 'Any' } RecipientScope = if ($rule.SentToScope) { $rule.SentToScope } else { 'Any' } Conditions = ($rule.Conditions | ForEach-Object { $_.ToString() }) -join '; ' Actions = ($rule.Actions | ForEach-Object { $_.ToString() }) -join '; ' Exceptions = ($rule.Exceptions | ForEach-Object { $_.ToString() }) -join '; ' Comments = $rule.Comments MigrationConcerns = $concerns -join '; ' } } } |