#Export
Get-Mailbox -Filter {ForwardingAddress -ne $null -or ForwardingSmtpAddress -ne $null} |
Select-Object DisplayName, UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward |
Export-Csv -Path "C:\EmailForwarding.csv" -NoTypeInformation -Encoding UTF8
#Import
$forwardingData = Import-Csv -Path "C:\EmailForwarding.csv"
foreach ($row in $forwardingData) {
Set-Mailbox -Identity $row.UserPrincipalName `
-ForwardingSmtpAddress $row.ForwardingSmtpAddress `
-DeliverToMailboxAndForward $row.DeliverToMailboxAndForward
}