Set-ExchangeMailboxForwardConfig
Exchange: Configures email forwarding for a mailbox
#Requires -Version 5.1
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[string]$Identity,
[Parameter(Mandatory = $true)]
[string]$ForwardTo,
[bool]$DeliverToMailboxAndForward = $true,
[switch]$UseInboxRule,
[string]$RuleName
)
Process {
try {
if ($UseInboxRule.IsPresent) {
$name = if ($RuleName) { $RuleName } else { "Forward to $ForwardTo" }
New-InboxRule -Mailbox $Identity -Name $name -ForwardTo $ForwardTo -Confirm:$false -ErrorAction Stop
}
else {
Set-Mailbox -Identity $Identity -ForwardingAddress $ForwardTo -DeliverToMailboxAndForward $DeliverToMailboxAndForward -Confirm:$false -ErrorAction Stop
}
$result = [PSCustomObject]@{
Identity = $Identity
ForwardTo = $ForwardTo
ForwardingType = if ($UseInboxRule) { "InboxRule" } else { "ForwardingAddress" }
Action = "ForwardingConfigured"
Status = "Success"
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
Write-Output $result
}
catch {
throw
}
}Specifies the Identity of the mailbox to forward from.
Specifies the Identity of the recipient to forward messages to.
If set, a copy of the forwarded messages will be kept in the original mailbox.
Off
If set, creates an Inbox rule instead of using the standard ForwardingAddress attribute.
Optional. Specifies the name for the Inbox rule if UseInboxRule is enabled.