Solved

Removing a Disconnected Mailbox using PowerShell

Posted on 2011-02-24
5
2,382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 43

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 43

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
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…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

617 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