Solved

Removing a Disconnected Mailbox using PowerShell

Posted on 2011-02-24
5
2,372 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:jgrammer42
  • 2
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
Amit earned 500 total points
ID: 34973724
0
 
LVL 3

Expert Comment

by:vicoso
ID: 34973751
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 }
0
 

Author Comment

by:jgrammer42
ID: 34973861
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
0
 
LVL 42

Expert Comment

by:Amit
ID: 34973893
If you have a chance have a look at the link posted above
0
 

Author Closing Comment

by:jgrammer42
ID: 34973921
This Powershell cmdlet worked great!

Thank you,
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to install and use the NTBackup utility that comes with Windows Server.
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question