Determine if a Mailbox is On-Premises or in Office 365

About

Check user mailbox if it is on (on prem) exchange server or on O365.

 

 

Steps:

You will need to connect to O365 using PS. Use the connect script

 

 

Code:

 

# Connect to office 365

$credentials = Get-Credential

Write-Output “Getting the Exchange Online cmdlets”

   

$Session = New-PSSession -ConnectionUri https://outlook.office365.com/powershell-liveid/ `

    -ConfigurationName Microsoft.Exchange -Credential $credentials `

    -Authentication Basic -AllowRedirection

Import-PSSession $Session

 

Install-Module -Name AzureAD -force

Connect-AzureAD -Credential $credentials

install-module MSOnline -Force

Connect-MsolService -Credential $credentials

 

 

 

# Check user mailbox (on prem) exchange server or on O365

Get-MsolUser |

Where-Object isLicensed -eq $true |

Select-Object -Property DisplayName, UserPrincipalName, isLicensed,

                        @{label=’MailboxLocation’;expression={                        

                            switch ($_.MSExchRecipientTypeDetails) {

                                      1 {‘Onprem’; break}

                                      2147483648 {‘Office365’; break}            

                                      default {‘Unknown’}

                                  }

                        }}