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 {
[string]$SearchBase = "$((ActiveDirectory\Get-ADDomain).DistinguishedName)",
[int32]$ResultSetSize = 10000,
[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 | 

Nice, isn’t it? 😀

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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