Solved

Removing a Disconnected Mailbox using PowerShell

Posted on 2011-02-24
5
2,360 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 41

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 41

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
In this video we show how to create an Address List 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 Organization >> Ad…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now