Exchange and Invalid Mailboxes

#Exchange #Exchange2010 #Powershell

You know when you run Get-Mailbox using the Exchange Management Shell, and if your unlucky like me you have a shed load of mailboxes that are “invalid” for various reasons.   .. and when you run Get-Maibox you get red text that says the mailbox has an error, but you don’t know which mailbox.

So I knocked this up .. Enjoy .. as you may have guessed the result is InvalidMBX.html.  Not the most glamorous but does the trick

$allMailboxes = get-mailbox -ResultSize unlimited
$invalid = $allMailboxes | where {$_.IsValid -eq $False}

$InvalidMBX = @()
ForEach ($MBX in $Invalid){
  $tmpTable = “” | Select Name, Email, PropertyName,Description, InvalidData

  $mbxvalid = $MBX.Validate()
  $mbxValid | ForEach{
    $tmpTable.Name = $MBX.name
    $tmpTable.Email = $MBX.PrimarySmtpAddress.ToString()
    $tmpTable.PropertyName  = $_.PropertyName
    $tmpTable.Description   = $_.Description
    $tmpTable.InvalidData   = $_.InvalidData
  $InvalidMBX += $tmpTable
  }
}

$InvalidMBX | ConvertTo-Html | Out-File InvalidMBX.html

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 )

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.