An Exchange Online license was applied to the user before the Exchange GUID got synchronized from on-premises Active Directory. For synchronized accounts, having the Exchange GUID synchronized from on-premises is used to tell Exchange Online that the mailbox hasn’t been migrated yet, and is what allows customers to pre-license accounts prior to migration.From: My user has a mailbox both on-premises and in Exchange Online.
So, in my case many times we get into situation where license is applied before Exchange GUID is synchronized to O365. I am using this script to check whether user has two mailboxes. Script closes Exchange session BEFORE it opens connection to Exchange Online as both use same commands. You can use Get-Mailbox both on-prem and Online, therefore it is crucial to close connection before you open other.
# DISCLAIMER:
# This code is provided "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
# Use at your own risk
#
#
# Use "install-module ExchangeOnlineManagement" if module is not yet installed
# Use "import-module ExchangeOnline" to import it to session
# Connect to the on-premises Exchange server using remote PowerShell
$onPremisesExchangeServer = "on-premexchange.example.com"
$onPremisesSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$onPremisesExchangeServer/PowerShell/ -Credential exchadmin@example.com
Import-PSSession $onPremisesSession
$OnPremisesMailboxes = Get-Mailbox -server $onPremisesExchangeServer -ResultSize unlimited -RecipientType UserMailbox -Filter {ExchangeGUID -ne $null}
# Disconnect the remote PowerShell session to the on-premises Exchange server
Remove-PSSession $onPremisesSession
# Connect to Exchange Online PowerShell
Connect-ExchangeOnline -UserPrincipalName admin@example.onmicrosoft.com
# Initialize an array to store the users with both an on-premises and an Office 365 mailbox
$usersWithBothMailboxes = @()
# Loop through all mailboxes to check if any user has both an on-premises and an Office 365 mailbox
foreach ($OnPremisesMailbox in $OnPremisesMailboxes) {
$userIdentity = $OnPremisesMailbox.UserPrincipalName
$Office365Mailbox = Get-EXOMailbox -Identity $userIdentity -ErrorAction SilentlyContinue
# Check if the user has both a mailbox in Office 365 and a mailbox on-premises that is not remote
if ($Office365Mailbox -ne $null) {
Write-Host -BackgroundColor DarkRed -ForegroundColor White "User $userIdentity has both an on-premises and Office 365 mailbox"
$usersWithBothMailboxes += $userIdentity
}
}
# Check if any users were found with both an on-premises and an Office 365 mailbox
if ($usersWithBothMailboxes.Count -eq 0) {
Write-Host -BackgroundColor Green -ForegroundColor White "There are no users with both on-premises and Office 365 mailboxes"
}
# Disconnect from Exchange Online PowerShell
Disconnect-ExchangeOnline -Confirm:$false
# This code is provided "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
# Use at your own risk
#
#
# Use "install-module ExchangeOnlineManagement" if module is not yet installed
# Use "import-module ExchangeOnline" to import it to session
# Connect to the on-premises Exchange server using remote PowerShell
$onPremisesExchangeServer = "on-premexchange.example.com"
$onPremisesSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$onPremisesExchangeServer/PowerShell/ -Credential exchadmin@example.com
Import-PSSession $onPremisesSession
$OnPremisesMailboxes = Get-Mailbox -server $onPremisesExchangeServer -ResultSize unlimited -RecipientType UserMailbox -Filter {ExchangeGUID -ne $null}
# Disconnect the remote PowerShell session to the on-premises Exchange server
Remove-PSSession $onPremisesSession
# Connect to Exchange Online PowerShell
Connect-ExchangeOnline -UserPrincipalName admin@example.onmicrosoft.com
# Initialize an array to store the users with both an on-premises and an Office 365 mailbox
$usersWithBothMailboxes = @()
# Loop through all mailboxes to check if any user has both an on-premises and an Office 365 mailbox
foreach ($OnPremisesMailbox in $OnPremisesMailboxes) {
$userIdentity = $OnPremisesMailbox.UserPrincipalName
$Office365Mailbox = Get-EXOMailbox -Identity $userIdentity -ErrorAction SilentlyContinue
# Check if the user has both a mailbox in Office 365 and a mailbox on-premises that is not remote
if ($Office365Mailbox -ne $null) {
Write-Host -BackgroundColor DarkRed -ForegroundColor White "User $userIdentity has both an on-premises and Office 365 mailbox"
$usersWithBothMailboxes += $userIdentity
}
}
# Check if any users were found with both an on-premises and an Office 365 mailbox
if ($usersWithBothMailboxes.Count -eq 0) {
Write-Host -BackgroundColor Green -ForegroundColor White "There are no users with both on-premises and Office 365 mailboxes"
}
# Disconnect from Exchange Online PowerShell
Disconnect-ExchangeOnline -Confirm:$false
Comments
Post a Comment