GUI utility for reconnecting Exchange’s disconnected mailboxes

Tzahi Kolber
4 min readAug 18, 2019

--

In this blog, I will review a simple GUI utility based on PowerShell, which reconnects a disconnected mailbox to a user on Exchange On-Premises in a very easy way.

Disconnected mailbox overview

When you remove or disable mailbox, the mailbox that was deleted, still located inside the database, where it was located and activate before the disconnection process.
The default configuration, unless it was changed, is configured to store deleted mailboxes for 30 days.
This setting can be changed at the next location, per mailbox database:

Since Exchange 2013, there is a relatively comfortable way to reconnect a disconnected mailbox from EAC (Exchange Admin Center):

Of course, you can use PowerShell as well to connect a disconnected a mailbox by using the next command:

Connect-mailbox “Tzahi Kolber” -User tkolber -database DB01

Connecting mailboxes using EAC is a convenient way, using the GUI, but there is a tiny issue when you are facing large and massive environments with a lot of Exchange servers and databases.

  • Disconnected mailboxes are displayed by the Exchange server.
    So, in case you are having a lot of servers, it becomes a complex and time-consuming task for searching all servers for the desired mailbox.
  • On the other way, working with PowerShell to find and reconnect mailboxes is not an easy task for a novice Exchange Administrators.

For these reasons, I have decided to write a small GUI utility based on PowerShell, which gets all the disconnected mailboxes from all the servers into one list.
Using this utility, reconnecting mailboxes become an easier task in large, but also small Exchange environments.

The script process:

  • Using the Get-MailboxStatisctics command, the script checks for the disconnected mailboxes (disabled/removed) on every Exchange’s database in the organization.
    In large environments where there are tens of thousands of mailboxes, this step might take some time obviously.
    There could be more than one mailbox with the same name, but with a different Identity.
    Think about a situation where a mailbox was disabled (disconnected from a user), for example, User8 and after some time a new mailbox was created for that user.
    After some time the new mailbox was disabled as well.
    In such a situation, there will be 2 disconnected mailboxes with the same name, but with a different Identity.
    Therefore the list of disconnected mailboxes contains the name of the disconnected mailbox, the date where the mailbox was disconnected and the Identity of the mailbox:
  • Next, you just have to click the Connect button and connect the disconnected mailbox from the relevant date to the user you have selected.
  • The script currently doesn’t connect Archive mailboxes.

Permissions and prerequisites to run the script

To run the script we must have the Exchange Management Shell installed on the computer that runs the script:
https://docs.microsoft.com/en-us/exchange/plan-and-deploy/post-installation-tasks/install-management-tools?view=exchserver-2019

Or

Connect to a remote session to one of the existing Exchange servers: https://docs.microsoft.com/en-us/powershell/exchange/exchange-server/connect-to-exchange-servers-using-remote-powershell?view=exchange-ps

To run the script we need at least the Mail Recipient permissions.

Running the script

To run the script, just open the Exchange Management Shell (EMS) or from Windows PowerShell and connect to one of the Exchange servers and run the script.

  • Select the disconnected mailbox you would like to reconnect and the user to connect the mailbox to then click Connect:
  • In case that the process completed successfully, a green message will appear under the Connect button:
  • In case the process failed, a red message will appear under the Connect button:
  • The error will be saved as a default at the next location: “C:\Scripts\Connection_Result.txt

In case you would like to change the location and/or the name of the text file where the error is saved, just changed the path at the next location inside the beginning of the script to the selected path:

$ErrPath=”C:\Scripts\Connection_Result.txt

The script

--

--

Tzahi Kolber
Tzahi Kolber

Written by Tzahi Kolber

During the last 17 years, I was working as a Senior PFE within Exchange area at Microsoft. Now I’m Senior Consult as Azure IAAS, DevOps & Automations.

No responses yet