Skip to main content

SYNOPSIS

Creates Exchange Online transport (mail flow) rules from one or more JSON definition files.

SYNTAX

DESCRIPTION

This function reads JSON files describing Exchange Online transport rules and provisions them by splatting their content to New-TransportRule. The recommended layout is one JSON file per rule, which makes the rule set version-controllable and reproducible across tenants. Each JSON file must be a single object whose keys match New-TransportRule parameter names. If a rule with the same Name already exists in the tenant, the rule is skipped (use -Force to recreate it after deletion). Supports -WhatIf and -Confirm via SupportsShouldProcess. Use -GenerateCmdlets to emit the equivalent New-TransportRule cmdlets to a file instead of executing them. The function expects a connected ExchangeOnlineManagement session (Connect-ExchangeOnline).

EXAMPLES

EXAMPLE 1

New-ExTransportRuleFromJson -Path “C:\eop-rules\Block-Outbound-OnMicrosoft.json” Creates a single transport rule from the specified JSON file.

EXAMPLE 2

Lists every transport rule that would be created from the JSON files in the directory without applying any change.

EXAMPLE 3

Creates every rule defined in the directory; pre-existing rules with the same Name are removed first.

EXAMPLE 4

Emits the equivalent New-TransportRule cmdlets to the specified file without executing them. Useful for review or for running the rule provisioning from another host.

PARAMETERS

-Path

Path to a JSON file or to a directory containing one or more JSON files. When a directory is provided, every *.json file in the directory is processed in alphabetical order.

-Force

If a rule with the same Name already exists, remove it before creating the new one. Without this switch, existing rules are skipped with a warning.

-GenerateCmdlets

If specified, the function generates the New-TransportRule cmdlets and saves them to a file instead of executing them.

-OutputFile

Path to the output file used by -GenerateCmdlets. If omitted while -GenerateCmdlets is set, defaults to a timestamped file in the user profile (cross-platform). Ignored unless -GenerateCmdlets is specified.

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

-Confirm

Prompts you for confirmation before running the cmdlet.

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES

Prerequisites:
  • PowerShell 5.1 or later. JSON content is converted to an ordered hashtable through a local helper to stay compatible with Windows PowerShell 5.1, which does not support ConvertFrom-Json -AsHashtable.
  • ExchangeOnlineManagement module installed and an active session opened with Connect-ExchangeOnline before running the function (unless -GenerateCmdlets is specified, which only emits the cmdlet text).
  • The signed-in account must hold a role with permission to manage mail flow rules, typically Exchange Administrator or a member of the Organization Management role group.
https://ps365.clidsys.com/docs/commands/New-ExTransportRuleFromJson