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


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




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





# Connect to office 365

$credentials = Get-Credential

Write-Output “Getting the Exchange Online cmdlets”


$Session = New-PSSession -ConnectionUri `

    -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,


                            switch ($_.MSExchRecipientTypeDetails) {

                                      1 {‘Onprem’; break}

                                      2147483648 {‘Office365’; break}            

                                      default {‘Unknown’}