Powershell Needful Things put that in your pipeline

Exchange 2010 User Cleanup

The Exchange 2010 user mailbox cleanup tool, is a free tool which Exchange Administrators can use to cleanup stale or unused mailboxes from Exchange 2010 mailbox servers.

The tool is executed as a Powershell script which opens up a GUI interface as seen above. The reason for the GUI is to allow Exchange server administrators to delegate this function to the recipient administrators without a huge learning curve.

When you launch the tool, you select the mailbox server against which you want to run a query or cleanup. Once you have selected your server, you can select any of the predetermined queries, to help you locate user mailboxes to remove. These are:

Disabled - Mailboxes linked to disabled Active Directory accounts.
Hidden - Mailboxes which are hidden from the Global Address List.
Stale - Mailboxes linked to Active Directory accounts which have not logged on in 90 days.

Once the query is complete, the results are listed with a calculation of the approximate size of the accounts. You can now shift-click or control-click to select accounts against which you want to perform cleanup actions.

The following actions are available:

Export list - Export the list of users to a text file, as a backup or to submit change control requests
Rename - Rename the accounts based on the query used to find the, (DISABLED-XXX, or HIDDEN-XXX etc.)
Disable - Disable the mailbox, removing the mailbox and Active Directory association.
Delete - Delete the mailbox, leaving the Active Directory account in tact.
Move - Move the selected mailboxes to a "mothball" store for backup and removal.

Finally, there is a check box called "Go Live". None of these actions will have any impact on your environment unless this box is checked. This box removes the whatif parameter from the action buttons.

I am continually adding new features and functionality to the script, so subscribe for updates, or check in regularly for new versions. I intend to add a box to allow administrators to specify the stale account age, but I will do then when I have purchased Primal Forms.

Updated all cmdlets for use with Exchange 2010
Remove Export PST as this requires a 64bit version of Windows, Outlook and the Exchange Management Tools

V1.3 (Final)
Added one more search query button, the “Last Logon” button. This button will look for users on the selected server where the LastLogon is equal to $null. This finds accounts which have essentially never logged on. There is a small bug though, if the user name is not unique, it seems that the last logon is unreadable and the account will also show up in the list.

After completing a query, the utility will now show you the total amount of data used by the mailboxes. (this obviously ignores single instance storage etc.)
You can now use the utility to move selected mailboxes to another store
I have force removed the mandatory “confirm” on the Exchange verbs (move, disabled and delete)

Basic GUI with all features enabled.

WARNING: This is a dangerous utility, and can wreck your Exchange system if you are not careful. Please test this in your test environment first, and adhere to your change control procedures before using this utility in the live environment. I take absolutely no responsibility for any damage caused by using this tool. The utility requires the Exchange Management shell, and if launched from a Vista / Windows 7 needs to be “Run as Administrator”

If you like this script and use it in production, please help me keep this project free by considering a small donation.

The script can be downloaded from here:

Comments (21) Trackbacks (2)
  1. I love this tool, thanks so much. I’d like to include a ‘lastlogontime’ in the exported results so we can see how long each of the stale mailboxes have been stale. I’ve tried picking thru the code but am not sure where to add it as there are so many variables.

    Thanks so much!

  2. When I run the script, I get this:
    Cannot bind argument to parameter ‘Identity’ because it is null.
    + CategoryInfo : InvalidData: (:) [Get-MailboxStatistics], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-MailboxStatistics

    • Alberto,

      Thank you for downloading the script. Did you run it in the 2010 management console?

      Please post a screenshot of this error. I have just tested it again, on my test server and I was unable to simulate the error.



  3. Great tool, anyone know what I would need to change to set a longer period, say 12 months?


    • Ciaran,

      Thanks for downloading. There is a line:

      Where {$_.LastLogonTime -le ((get-date).AddDays(-90)

      You can increase the -90 to the required days.


  4. Jean,
    You have really put together some great scripts. I was wondering if you have written up anything in regards to the “mothball” store for backup and removal? I would like to move our stale accounts over to such a thing, but I don’t want to have any user CALS used up. Any feedback would be appreciated.


    • Hi there Mark,

      Sorry for the late reply, I have had some access issues to my blog. Please could you tell me what you need?



  5. Good afternoon,

    When I run the script, the database field is empty. The exchange database is not stored on the C drive of the server. Any insight?

    Thank you

    • Hi there,

      Sorry for the late reply, I have had some access issues to my blog. Did you run the script on the Exchange server?


  6. When I run the script the Export PST option is disabled. Can you tell me how to re-enable this?

  7. I don’t see the link to the script…it just says “{filelink=7}”?

  8. Link unavailable 🙁

Leave a comment