Quick post: find users who have an Exchange Online mailbox

If you have a hybrid Exchange infrastructure, it appears that you can query your local Active Directory to find out users who have already been migrated to Exchange Online.

Thanks to the attribute named msExchRecipientTypeDetails (values detailed here), you can find these accounts with a remote mailbox.

Here’s a small function that leverages this msExchRecipientTypeDetails attribute:

Function Get-RemoteUserMailbox {
[CmdletBinding()]
Param(
[Parameter()]
[string]$SearchBase = "$((ActiveDirectory\Get-ADDomain).DistinguishedName)",
[Parameter()]
[int32]$ResultSetSize = 10000,
[Parameter()]
[string]$SearchScope = 'SubTree'
)
Begin {}
Process {
$HT = @{
Filter = 'msExchRecipientTypeDetails -eq 2147483648'
SearchScope = $SearchScope
ResultSetSize = $ResultSetSize
SearchBase = $SearchBase
ErrorAction = 'Stop'
}
try {
ActiveDirectory\Get-ADUser @HT
} catch {
Write-Warning -Message "Failed to query AD because $($_.Exception.Message)"
}
}
End {}
}

You can even bind cmdlets like this for example:

Get-RemoteUserMailbox  |
Get-ADUser -Properties AccountExpirationDate | 
Out-GridView

Nice, isn’t it? 😀

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.