The below is a little example of how to extract a list of the configured Office 365 email forwarding settings using the cmdlet get-mailbox for all mailboxes
Three columns will be returned;
- UserPrincipalName: The users Office 365 username
- ForwardSmtpAddress: If defined this is the email address messaged are being forwarded to, else forwarding is not enabled.
- DeliverToMailboxAndForward: If set to true a copy is keep in the mailbox in addition to being forwarded, else no local copy is retained.
Connecting to Office 365
$UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session
Displaying as a list in the PowerShell window
Get-Mailbox | select UserPrincipalName,ForwardingSmtpAddress,DeliverToMailboxAndForward
Exporting the list as a CSV file
Get-Mailbox | select UserPrincipalName,ForwardingSmtpAddress,DeliverToMailboxAndForward | Export-csv D:\Office365Forwards.csv -NoTypeInformation
I’m getting the below error:
Import-PSSession : Running the Get-Command command in a remote session reported the following error: Processing data for a remote command failed with the following error message: The WinRM client cannot process the request because the server name cannot be resolved.
Hi,
“the server name cannot be resolved” would suggest a DNS or network issues. Can you ping the remote computer by name and/or IP?
Phil
Should try this tips
Phil,
Is it correct that forwarding is configured only if ForwardingSmtpAddress is populated, regardless of whether DeliverToMailboxAndForward is TRUE? Also, does this account for server-side forwarding rules only?
Hi,
Yes that is correct all that is required for emails to forward is for ForwardingSmtpAddress to be populated.
If DeliverToMailboxAndForward is set to true then a copy of the email will remain in the mailbox a copy will be forwarded to the address in ForwardingSmtpAddress.
If DeliverToMailboxAndForward is set to false the mail is just forwarded and no copy is left in the mailbox.
My understanding is that it doesn’t matter how the forwarding rule(s) have been created whether that be using Outlook, Outlook web or on the admin side of the fence. The forwarding rule is applied to Excahnge is the same way and exposed using this PowerShell. Does that answer your question?
Thanks
Phil
I get that Get-Mailbox is not a cmdlet or… I did all recommended (64bit, admin rights at powershell and office etc) but Get-Mailbox is not available.
We have a need to temporarily forward all inboxes in O365 Outlook to our on-prem Exchange server. How would we use a version of this script to do that?
This is nice tip…. Thank You
Fantastic! Just what I was looking for!