These scripts check whether a mailbox does or does not contain an email address. This is a great way to find out which mailbox in an organisation contains a certain email address.
Check if an email address is on a mailbox:
get-mailbox | where {$_.EmailAddresses -like "*@emailaddress.com"}
Check if an email address is NOT on a mailbox:
get-mailbox | where {-not ($_.EmailAddresses -like "*@emailaddress.com")}
Another way to check that an email address is not on a mailbox is to cycle through the EmailAddresses array:
Get-Mailbox | foreach {
For ($i=0;$i –lt $_.EmailAddresses.Count;$i++)
{
$address = $_.EmailAddresses[$i]
If($address.SmtpAddress –like "*@test.com")
{
Write-Host $_.Name
Break
}
}
}
Friday, May 14, 2010
Exchange: Check if email addresses are or are not on a mailbox in Exchange 2007
Labels:
Exchange 2007,
Exchange 2010,
powershell,
Scripting
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment