Link to home
Start Free TrialLog in
Avatar of jgrammer42
jgrammer42

asked on

Removing a Disconnected Mailbox using PowerShell

I am using Exchange 2010 SP1.  While I was setting things up, I created 4 test accounts.  Now that everything is working, I deleted those test accounts from the Recipient Configuration\Mailbox area.  Now they are sitting in the Disconnected Mailbox area.

I found a Powershell script from Technet that I have been trying to use to permanently delete these mailboxes, but cannot get it to work.  The example script is this:

$Temp = Get-Mailbox | Where {$_.DisplayName -eq 'John Rodman'}
Remove-Mailbox -Database Server01\Database01 -StoreMailboxIdentity $Temp.MailboxGuid

However, when I execute these cmdlets the first one executes, but does NOT return the GUID value into the $Temp variable.  And then obviously the 2nd cmdlet fails with the error saying that -StoreMailboxIdentity has a 'null' value.

Does anyone have any experience successfully executing these scripts?  Or does anyone have a better and working method of permanently removing mailboxes from the Disconnected Mailbox area?

Thank you in advance,
Jeff
ASKER CERTIFIED SOLUTION
Avatar of Amit
Amit
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vicoso
vicoso

Listing all disconnected mailboxes
Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid

Removing all users at the same time
$users = Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid
 
Now that we have all disconnected mailboxes in a var, we can run the following cmdlet to remove all of them:
$users | ForEach { Remove-Mailbox -Database "Mailbox Database" -StoreMailboxIdentity $_.MailboxGuid -confirm:$false }
Avatar of jgrammer42

ASKER

vicoso,

I get an error on the cmdlet of Get-MailboxStatistics, on the "where-object" parm.

I tried using both "where -object" and "where-object" (thinking I needed a space between the dash and the where).

The error(s) I get are as follows:
(Using 'where-object'): Where-Object : A positional parameter cannot be found that accepts argument 'Select'

(Using 'where -object'): Where -Object : A parameter cannot be found that matches parameter name 'object'.

Any suggestions?

Thank you,
Jeff
If you have a chance have a look at the link posted above
This Powershell cmdlet worked great!

Thank you,