Exchange 2010 PowerShell: Verify Email Address Existence and Find Associated Mailbox/Group


2 views

When migrating Exchange environments, one critical verification step is ensuring all email addresses (primary SMTP and aliases) have been properly transferred. The traditional GUI methods become impractical when dealing with hundreds or thousands of addresses.

Exchange 2010's management shell provides powerful cmdlets for address verification. Here's the most comprehensive approach:

# Basic verification command:
Get-Recipient -Identity "user@domain.com" -ErrorAction SilentlyContinue

# Enhanced version with ownership details:
$email = "helpdesk@company.com"
$result = Get-Recipient -Identity $email -ErrorAction SilentlyContinue | 
          Select-Object Name, RecipientType, PrimarySmtpAddress, EmailAddresses

if ($result) {
    Write-Host "Address found:"
    $result | Format-List
} else {
    Write-Host "Address not found in the system"
}

For complex migration scenarios, consider these additional approaches:

# Check all proxy addresses (including aliases):
Get-Mailbox -ResultSize Unlimited | 
Where-Object {$_.EmailAddresses -like "SMTP:*helpdesk@company.com*"} |
Select-Object Name, PrimarySmtpAddress

# Distribution group verification:
Get-DistributionGroup -ResultSize Unlimited | 
Where-Object {$_.EmailAddresses -like "*support@company.com*"}

Here's a complete script I've used in production environments:

# MigrationAddressAudit.ps1
param (
    [Parameter(Mandatory=$true)]
    [string]$EmailAddress,
    [switch]$Detailed
)

$recipient = Get-Recipient -Identity $EmailAddress -ErrorAction SilentlyContinue

if (-not $recipient) {
    Write-Output "NOT FOUND: $EmailAddress"
    exit 1
}

$output = [PSCustomObject]@{
    Address      = $EmailAddress
    DisplayName  = $recipient.DisplayName
    Type         = $recipient.RecipientType
    PrimaryEmail = $recipient.PrimarySmtpAddress
}

if ($Detailed) {
    $output | Add-Member -NotePropertyName "Aliases" -NotePropertyValue $recipient.EmailAddresses
    $output | Add-Member -NotePropertyName "OU" -NotePropertyValue $recipient.OrganizationalUnit
}

$output

When checking large numbers of addresses:

  • Use -ResultSize Unlimited for complete results
  • Cache recipient data in variables if checking multiple addresses
  • Consider using Start-Transcript for audit trails

Watch out for these issues:

# Case sensitivity gotcha (Exchange is case-insensitive but PowerShell isn't):
Get-Recipient -Identity "User@Domain.com"  # Might fail
Get-Recipient -Identity "user@domain.com"  # Preferred

When migrating email systems or performing Exchange maintenance, administrators often need to verify whether specific email addresses exist in the system and identify their associated objects. Exchange 2010's PowerShell module provides powerful cmdlets to accomplish this.

The most comprehensive solution is to use Get-Recipient, which can query all mail-enabled objects:

Get-Recipient -Identity "user@domain.com" | Select-Object Name,RecipientType,PrimarySmtpAddress,EmailAddresses

This command will return:

  • The object's display name
  • Recipient type (UserMailbox, MailUser, MailContact, DistributionGroup, etc.)
  • Primary SMTP address
  • All email addresses associated with the object

For Mailboxes Only

If you specifically need to check mailbox objects:

Get-Mailbox -Identity "user@domain.com" -ErrorAction SilentlyContinue

For Distribution Groups

To verify distribution group membership:

Get-DistributionGroup -Identity "group@domain.com" -ErrorAction SilentlyContinue

Here's a script to check multiple addresses from a CSV file:

$emailList = Import-Csv "C:\temp\emails.csv"
$results = @()

foreach ($email in $emailList) {
    $recipient = Get-Recipient -Identity $email.Address -ErrorAction SilentlyContinue
    
    if ($recipient) {
        $result = [PSCustomObject]@{
            EmailAddress = $email.Address
            ObjectType = $recipient.RecipientType
            ObjectName = $recipient.Name
            PrimaryAddress = $recipient.PrimarySmtpAddress
        }
        $results += $result
    }
    else {
        $results += [PSCustomObject]@{
            EmailAddress = $email.Address
            ObjectType = "Not Found"
            ObjectName = "N/A"
            PrimaryAddress = "N/A"
        }
    }
}

$results | Export-Csv "C:\temp\results.csv" -NoTypeInformation

Consider these scenarios:

  • Addresses with special characters (use single quotes)
  • Multiple matches (use -ResultSize Unlimited for large environments)
  • Address policies affecting primary addresses

For large environments:

  • Add -ResultSize Unlimited to ensure complete results
  • Consider filtering first if you know the expected object type
  • Cache results if running multiple queries