-
Notifications
You must be signed in to change notification settings - Fork 0
Set SMTPForward
Configures SMTP forwarding on Exchange Online mailboxes in bulk. Supports setting, clearing, or toggling DeliverToMailboxAndForward for any number of mailboxes via CSV file, in-memory array, or single-user parameters. Commonly used during tenant migrations, offboarding workflows, and domain transitions.
-
Set or clear forwarding — Set
ForwardingSmtpAddressor leave blank to clear it -
Deliver-to-mailbox control — Toggle
DeliverToMailboxAndForwardper mailbox - Bulk operation — CSV file, array, or single-identity input
-
Auto-forward policy management — Optional
-AllowAutoForwardupdates the tenant outbound spam filter to permit external auto-forwarding - WhatIf support — Preview all changes without applying them
- Timestamped CSV report — Full per-mailbox results
-
Template generation —
-GenerateTemplatecreates a pre-formatted input CSV
- PowerShell 5.1 or later (PowerShell 7 recommended)
Install-Module ExchangeOnlineManagement -Scope CurrentUser| Role | Purpose |
|---|---|
| Exchange Online Administrator or Exchange Recipient Administrator | Set forwarding on mailboxes |
| Exchange Online Administrator | Update outbound spam filter policy (-AllowAutoForward) |
| Parameter | Type | Description |
|---|---|---|
-CsvPath |
String | Path to CSV file. Required columns: Identity, ForwardingAddress, DeliverToMailboxAndForward. |
-UserArray |
Object[] | Array of PSCustomObjects/hashtables with the same properties as the CSV. |
-Identity |
String | Single mailbox UPN or SMTP address. Use with -ForwardingAddress. |
| Parameter | Default | Description |
|---|---|---|
-ForwardingAddress |
"" |
Target SMTP address. Leave empty to clear forwarding. |
-DeliverToMailboxAndForward |
$true |
Keep a copy in the original mailbox while forwarding. |
| Parameter | Description |
|---|---|
-AllowAutoForward |
Updates the Default outbound spam filter policy to AutoForwardingMode = On. Tenant-wide change — use only with documented approval. |
-WhatIf |
Simulate all changes without applying them. |
| Parameter | Default | Description |
|---|---|---|
-OutputDirectory |
C:\Reports\CSV_Exports |
Directory where the results CSV is saved. |
-GenerateTemplate |
— | Creates a blank CSV template and exits. |
Identity,ForwardingAddress,DeliverToMailboxAndForward
jsmith@contoso.com,jsmith@fabrikam.com,TRUE
agarcia@contoso.com,agarcia@fabrikam.com,FALSE
departed@contoso.com,,FALSE| Column | Required | Description |
|---|---|---|
Identity |
Yes | UPN or primary SMTP of the source mailbox |
ForwardingAddress |
Yes | Target SMTP address. Leave blank to clear forwarding. |
DeliverToMailboxAndForward |
Yes |
TRUE = keep a copy in source mailbox; FALSE = forward only |
Note: A blank
ForwardingAddresswith anyDeliverToMailboxAndForwardvalue will clear forwarding from the mailbox.
| Column | Description |
|---|---|
Identity |
Source mailbox identity |
ForwardingAddress |
Forwarding address that was set or cleared |
DeliverToMailboxAndForward |
Value applied |
Status |
Success / Cleared / WhatIf-Set / WhatIf-Clear / Failed |
Details |
Additional context for warnings or errors |
Timestamp |
Time the mailbox was processed |
.\Set-SMTPForward.ps1 -Identity "jsmith@contoso.com" -ForwardingAddress "jsmith@fabrikam.com"Keeps a copy in the original mailbox (default: DeliverToMailboxAndForward = $true).
.\Set-SMTPForward.ps1 -Identity "jsmith@contoso.com" `
-ForwardingAddress "jsmith@fabrikam.com" `
-DeliverToMailboxAndForward $false.\Set-SMTPForward.ps1 -Identity "jsmith@contoso.com"Omitting -ForwardingAddress clears any existing forwarding.
.\Set-SMTPForward.ps1 -CsvPath "C:\Data\forwards.csv".\Set-SMTPForward.ps1 -CsvPath "C:\Data\forwards.csv" -AllowAutoForward.\Set-SMTPForward.ps1 -CsvPath "C:\Data\forwards.csv" -WhatIf$forwards = @(
[PSCustomObject]@{ Identity = "alice@contoso.com"; ForwardingAddress = "alice@fabrikam.com"; DeliverToMailboxAndForward = $true }
[PSCustomObject]@{ Identity = "bob@contoso.com"; ForwardingAddress = "bob@fabrikam.com"; DeliverToMailboxAndForward = $false }
[PSCustomObject]@{ Identity = "old@contoso.com"; ForwardingAddress = ""; DeliverToMailboxAndForward = $false }
)
.\Set-SMTPForward.ps1 -UserArray $forwards.\Set-SMTPForward.ps1 -GenerateTemplate -OutputDirectory "C:\Data"
# Creates: C:\Data\SMTPForward_Template.csvBy default, Microsoft 365 tenants block external auto-forwarding via the outbound spam filter. The -AllowAutoForward switch updates the Default outbound spam filter policy to AutoForwardingMode = On, which is a tenant-wide setting. This should only be used when:
- External forwarding is a documented business requirement
- The change has been reviewed and approved
- You plan to revert it after the migration or task is complete
AutoForwardingMode values:
| Value | Behavior |
|---|---|
Automatic |
Respects Remote Domain auto-forward setting (default) |
On |
Permits auto-forwarding regardless of Remote Domain settings |
Off |
Blocks all auto-forwarding tenant-wide |
A blank or empty ForwardingAddress value in CSV or array will call Set-Mailbox -ForwardingSmtpAddress $null, which removes any existing forwarding configuration.
If you are already connected to Exchange Online in the same session, the script detects the existing connection and reuses it without prompting for credentials again.
Output file: C:\Reports\CSV_Exports\SMTPForward_Results_YYYYMMDD_HHmmss.csv
If forwarding is configured correctly but emails are not arriving at the destination, check the outbound spam filter policy. Run with -AllowAutoForward or manually set:
Set-HostedOutboundSpamFilterPolicy -Identity Default -AutoForwardingMode OnVerify the UPN or primary SMTP address. The account must have an Exchange Online mailbox.
Install-Module ExchangeOnlineManagement -Scope CurrentUserYou may need to confirm the exact target address with the destination tenant before setting up forwarding. Unconfirmed onmicrosoft.com addresses should be skipped until verified.
-
v1.0 (2026-03-13): Initial release — bulk SMTP forwarding, clear support, array/CSV/single input,
-AllowAutoForward, WhatIf, template generation
- Microsoft Docs: Set-Mailbox
- Microsoft Docs: Set-HostedOutboundSpamFilterPolicy
- Set-EmailToSharedAccount — Convert mailboxes to Shared and remove licenses
- Invoke-UserSignOutAndBlock — Block sign-in and revoke sessions
- Overview
- Start-LyncCsvExporter
- Get-ComprehensiveLyncReport
- Get-LyncHealthReport
- Get-LyncInfrastructureReport
- Get-LyncServiceStatus
- Get-LyncUserRegistrationReport
- Export-ADLyncTeamsMigrationData
- New-Office365Accounts
- Sync-ContactsFromCsv
- Set-EmailToSharedAccount
- Set-SMTPForward
- Invoke-UserSignOutAndBlock
- Security Assessment Scripts (coming soon)
- Azure Automation (documentation pending)
- Get-GraphToken
- Get-GraphHeaders
- Get-AzureResourcePaging
- Get-EnterpriseAppUsage
- Get-ExchangeErrorsGraph
- Get-PBIWorkspaceUsageReport
- Intune Management (documentation pending)