How to forcefully delete all the disconnected mailboxes at one go \ batch by batch.


I have 100 of users who have left our organisation in the past and their mailboxes has not been deleted.
Now I have deleted their mailboxes and lists all the deleted mailbox with their Display names and MailboxGuid , when I give the following command.

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

I know how to forcefully delete the mailbox by entering the following command and putting the relevant MailboxGuid one by one. It  will take lot of time if I go on this method.

[PS] C:\Windows\system32>Remove-Mailbox -Database "Mailbox Database" -StoreMailboxIdentity "a31fb8b5-14ee-4509-834e-409d2ea3fe38" -confirm:$true

Are you sure you want to perform this action?
Removing store mailbox "a31fb8b5-14ee-4509-834e-409d2ea3fe38" on database
"Exchange.domain.local\Mailbox Database".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"):y
[PS] C:\Windows\system32>

Is there a easy way of forcefully deleting the  disconnected mailboxes at one go.

Any help will be great.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Muhammad BurhanManager I.T.Commented:
please giva a try with RemDisMB.ps1
$disabledmailboxes = @()
$disabledmailboxes = Get-MailboxStatistics -Database <mailboxDatabaseName> | where {$_.DisconnectReason -eq "Disabled"}

foreach ($mailbox in $disabledmailboxes) {
#define variables
$strIdentity = $mailbox.DisplayName
$strDatabase = $mailbox.database
$strState = $mailbox.DisconnectReason

Remove-StoreMailbox -Database $strDatabase -Identity $strIdentity -MailboxState $strState}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AmitIT ArchitectCommented:
Easy way is to decrease the delete mailbox retention period at db level. Rest Exchange will take care for you, no need to run any script or do anything manually, once you reduce deleted mailbox retention policy.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.