Skip to content

Remove mailboxes for disabled users

by Dieter on June 14th, 2010

Today I had to export the user mailboxes for all users who were disabled in Active Directory.
I used the following Powershell commands to make this happen.

The first step is to get a list of the mailboxes for all disabled users in Active Directory

[PS] C:\> $mailboxlist = Get-Mailbox -Server yourservername | ? {$_.UserAccountControl -match “AccountDisabled” -and $_.isLinked -match “false” -and $_.isResource -match “false”}

The next step is to add the necessary permissions to the mailbox to be able to export it and afterwards export it to a specified directory

[PS] C:\> foreach ($mailbox in $mailboxlist) {
Add-MailboxPermission -Identity $mailbox -AccessRights fullaccess -User
yourusername
Export-Mailbox -Identity $mailbox -PSTFolderPath c:\temp\ -Confirm:$false
}

Note that you can only run the Export-Mailbox command on a 32-bit computer with the Outlook client installed.

One Comment
  1. john permalink

    thanks !

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS