Solved

Removing a Disconnected Mailbox using PowerShell

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

912 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

21 Experts available now in Live!

Get 1:1 Help Now