How to get mailboxes where there is a forward set in Office 365 using PowerShell

This is a quick script to show you how to get mailboxes where there is a forward set in Office 365 using PowerShell

Run the below code:

$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential 

$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $UserCredential -Authentication "Basic" -AllowRedirection

Import-PSSession $exchangeSession -DisableNameChecking 


Get-Mailbox | Where {$_.ForwardingAddress -ne $null} | select UserPrincipalName,ForwardingAddress,ForwardingSmtpAddress,DeliverToMailboxAndForward | Export-Csv c:\temp\forwards.csv -nti 

Leave a Reply

Your email address will not be published. Required fields are marked *