Add mail forward powershell

Here are the steps to add a mail forward using PowerShell:

Prerequisites:

Step 1: Connect to Exchange Online

Run the following command to connect to Exchange Online:

$cred = Get-Credential
Connect-ExchangeOnline -Credential $cred

This will prompt you to enter your Exchange Online credentials.

Step 2: Get the mailbox

Run the following command to get the mailbox object:

$mailbox = Get-Mailbox -Identity <mailbox_name>

Replace <mailbox_name> with the name of the mailbox you want to add the mail forward to.

Step 3: Add the mail forward

Run the following command to add the mail forward:

Add-MailboxForwarding -Mailbox $mailbox.Identity -ForwardTo <forward_to_email>

Replace <forward_to_email> with the email address you want to forward the mail to.

Example:

$mailbox = Get-Mailbox -Identity "john.doe"
Add-MailboxForwarding -Mailbox $mailbox.Identity -ForwardTo "[email protected]"

This will add a mail forward from the mailbox "john.doe" to "[email protected]".

Step 4: Verify the mail forward

Run the following command to verify the mail forward:

Get-MailboxForwarding -Mailbox $mailbox.Identity

This will display the mail forward settings for the mailbox.

That's it! The mail forward should now be added and any emails sent to the mailbox "john.doe" will be forwarded to "[email protected]".