First,disconnected mailboxes
1,finding disconnected mailboxes
The first function is called Get-disconnectedmailbox and the name are pretty much self explanitory. This function would give you a list of all disconnected mailboxes on each of the your mailbox servers. Take a look at the following code:
functionget-Disconnectedmailbox {[Cmdletbinding ()]param([Parameter (Position=0, mandatory=$false)] [System.String]$Name= ' *')$mailboxes= get-MailboxServer$mailboxes| %{ $disconn= Get-mailboxstatistics-server$_. name |? {$_. Disconnectdate-ne $null } $disconn| ? {$_. displayname-like $Name} |Select DisplayName,@{n="storemailboxidentity"; e={$_. Mailboxguid}}, Database}}
View Code
Note: If you've recently deleted a mailbox, but it's not showing on when running Get-disconnectedmailbox, you M ay need to force Exchange to recognize this by running the Clean-mailboxdatabase cmdlet.
2,purging disconnected mailboxes
You purge mailboxes using the Remove-mailbox cmdlets, specifying the storemailboxidentity and Database for the disconnected Mailbox in question. For a good example of the, check out Nitin Gupta's post on removing disconnected mailboxes.
In a effort to simplify the purging of disconnected mailboxes, I wrote the Remove-disconnectedmailbox function which is de Signed to work with Get-disconnectedmailbox. Here is the code:
functionremove-Disconnectedmailbox {[Cmdletbinding (supportsshouldprocess=$true)] param([Parameter (Position=0, Valuefrompipelinebypropertyname=$true, mandatory=$true)] [System.String]$StoreMailboxIdentity, [Parameter (Position=1, Valuefrompipelinebypropertyname=$true, mandatory=$true)] [System.String]$Database ) Process{Remove-mailbox @Psboundparameters}}
View Code
Get-disconnectedmailbox "Bill Jones" | Remove-disconnectedmailbox-confirm:$false
$_. Storemailboxidentity-database ' db1′-user ' contoso\bboyer '-alias ' Bboyer '}
Reference to Blog
Two
Several methods of Powershell Get Domain mailbox